Player Character animation question

First, question: For my player sprite, I think i’ll have a static Torso and Head and then paint arms and legs which are rotateable objects, is this a good way to handle animation to look like movement eg running etc.
Also how do I handle rotations properly?
Second, so I think i’ve come up with a way to add custom armor to a sprite and animate it(asking if this is efficent). 1)Get base image Torso and head 2) Draw armor Head and torso 3) draw Arms and legs, 4) Arms and legs append to the Torso and these arms and legs can rotate and move.

So is this a good way of handling these circumstances? Thanks in advance.

Old school way,

have multiple sprites as frame and change them when updating game logic after some time passed.

I mean do you think for adding armor treating the arms and legs ad separate images is the best way to animate, So Head and torso same image and then arms and legs are separate. This way I can create better character customization? Also i’m having problems rotating parts of an image, what is the best way to rotate an image on an axis like say a arm that has a reference pixel for the shoulder and I want it to rotate up and down in a half circle like basis?

SO say this is a sprite arm.
sprite.drawImage(sp.imgArray().get(sp.getFrame()), sp.getX(), sp.getY(), this);//Monster Sprite

And the coordinates for the shoulder to rotate around is 30x 30y how can I achieve this?

Rather to have the code doing the position adjust, you’ll save time and memory by do it from outside. I mean, yes separate the static and dynamic part of sprites. Just be careful with offset. For example, you better have a dynamic sprite with some offset so it can be drawn with same coordinate as your static part sprite.

To rotate you can use rotate() of Graphics. However it’s quite slow.

So what do you recommended doing then? I’m a bit confused from your suggestion. And what do you mean by “Do it form out side”?. Also rotate() doesn’t work, any help with code to rotate on the fly trying to mimic movement arms up arms down etc.

I believe what Rebirth is trying to say is to perform your animation frames in an exterior program such as paint or photoshop. In a typical top down 2d game the set up of sprites you would use is,

Up1, Up2
Left 1, Left 2
Right 1, Right 2
Down 1, Down 2

While holding in the corresponding direction you swap back and forth between the two appropriate images. Also placing these different images on a single image and uploading them as sub images will save you some processor power.

Yup what Christopher said. But don’t think it as creating GIF image, avoid it! what you need to “do from outside” is adjusting sprites.


g2d.drawImage(playerBody, player.x, player.y, null); //image of static body
g2d.drawImage(playerSword, player.x, player.y, null); //image of sword

look how those two sprites share same coordinate. It can be done if the offset of playerSword is right. So you can save your time and have cleaner code.

Ok, I think I understand so.are you saying Instead of rotating I just get the coordinates? Regardless I still need to keep the sword in its proper position swinging, wont I have to adjust that with a dynamic rotate?

Depends on how smooth you want. Kev’s


sprite maybe can give you a point.

If you saw the graphics they had at mojam (http://www.google.ca/imgres?um=1&hl=en&sa=N&tbm=isch&tbnid=BCPPfsCWXPJWOM:&imgrefurl=http://www.reddit.com/user/4c51&docid=kapwIgwopANIoM&imgurl=http://i.imgur.com/Isnl2.png&w=317&h=687&ei=5xtYT_7-EvGp0AHYoM3kDw&zoom=1&iact=hc&vpx=1077&vpy=244&dur=435&hovh=331&hovw=152&tx=120&ty=180&sig=104825597772300283008&page=1&tbnh=155&tbnw=73&start=0&ndsp=15&ved=1t:429,r:9,s:0&biw=1280&bih=688), you could use the getSubimage() method (http://docs.oracle.com/javase/1.4.2/docs/api/java/awt/image/BufferedImage.html) to cycle between the rotations, and have a formula like so

img.getSubimage(animationFrame * 32, 0, 32, 32);

where animationFrame is the current frame in the animation, which you cycle when you move, and you would replace the 32 with the size of the image in pixels (I used 32, because that is what it is in the mojam graphics).

Then you would just set the sub image that you got as the image you draw, and when you walk it would draw the image.