Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Player Character animation question  (Read 6548 times)
0 Members and 1 Guest are viewing this topic.
Offline JayTech

Junior Devvie

Medals: 1

« Posted 2012-02-02 07:58:30 »

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.
Offline ReBirth
« Reply #1 - Posted 2012-02-03 03:07:53 »

Old school way,

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

Offline JayTech

Junior Devvie

Medals: 1

« Reply #2 - Posted 2012-02-03 07:19:09 »

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?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ReBirth
« Reply #3 - Posted 2012-02-04 02:49:58 »

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.

Offline JayTech

Junior Devvie

Medals: 1

« Reply #4 - Posted 2012-02-04 07:44:15 »

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.
Offline Christopher

Senior Devvie

Medals: 2
Projects: 1

« Reply #5 - Posted 2012-02-04 12:55:10 »

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.

Offline ReBirth
« Reply #6 - Posted 2012-02-05 02:45:08 »

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.

Offline JayTech

Junior Devvie

Medals: 1

« Reply #7 - Posted 2012-02-06 17:23:34 »

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?
Offline ReBirth
« Reply #8 - Posted 2012-02-08 02:44:26 »

Depends on how smooth you want. Kev's
sprite maybe can give you a point.

Offline sirlink99

Junior Newbie

« Reply #9 - Posted 2012-03-08 02:43:30 »

If you saw the graphics they had at mojam (,r:9,s:0&biw=1280&bih=688), you could use the getSubimage() method ( 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.
Pages: [1]
  ignore  |  Print  

EgonOlsen (45 views)
2018-06-10 19:43:48

EgonOlsen (27 views)
2018-06-10 19:43:44

EgonOlsen (47 views)
2018-06-10 19:43:20

DesertCoockie (211 views)
2018-05-13 18:23:11

nelsongames (128 views)
2018-04-24 18:15:36

nelsongames (127 views)
2018-04-24 18:14:32

ivj94 (868 views)
2018-03-24 14:47:39

ivj94 (129 views)
2018-03-24 14:46:31

ivj94 (780 views)
2018-03-24 14:43:53

Solater (144 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!