开发者

How to make a character from 6 bitmaps?

开发者 https://www.devze.com 2023-04-13 02:25 出处:网络
I have 6 different pictures that make up a character. The parts are: Right Hand, Left Hand, Head, Eyes, Shirt(body), and Pants(legs). what is the easiest part to make up the character? right now I\'m

I have 6 different pictures that make up a character. The parts are: Right Hand, Left Hand, Head, Eyes, Shirt(body), and Pants(legs). what is the easiest part to make up the character? right now I'm using one method that is to create them in an order and calculate everything, example:

       canvas.drawBitmap(handL, pX - handL.getWidth()+ (handR.getWidth()), pY - shirt.getHeight() + handL.getWidth(), null);
       canvas.drawBitmap(pants, pX , pY-handR.getWidth(), null);
       canvas.drawBitmap(shirt, pX, pY - shirt.getHeight(), null);
       canvas.drawBitmap(head, hX, hY, null);
       canvas.drawBitmap(handR, pX + shirt.getWidth() - (2 *handR.getWidth()/3), pY - shirt.getHeight() + handR.getWidth(), null);
       hX = pX - (handR.getWidth()/2) ;
       hY=pY - shirt.getHeight()- head.getHeight() +2;

it was hard to calculate everything but after half an hour i figured开发者_运维技巧 it out. I want an easier way because I'm going to have to use it many times and I don't want to rewrite it over and over.

thanks


A nice way to generate and update character parts is to work with sprites. You build up an image composed with every parts that your character will need, then you calculate the positions for each of them (pretty easy if all parts are for exemple 50x50). Then, you add the same image for every part, except that you display only the wanted part of it by changing display size and image position.

That way, you will never have to update an image path since all will depend on where you are in your sprites.

(I unforunately don't have worked on android yet, but a new thread have just been opened on how to make sprites in android : How to make sprites in Android)

Hope this helps

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号