Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  Player Character animation question  (Read 1340 times)
0 Members and 3 Guests are viewing this topic.
Offline JayTech

Jr. Member
**

Posts: 59
Medals: 1



« on: 2012-02-02 02: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

JGO Wizard
****

Posts: 1279
Medals: 19



« Reply #1 on: 2012-02-02 22:07:53 »

Old school way,

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

Follow me, your mastah, on TWITTAH!
Offline JayTech

Jr. Member
**

Posts: 59
Medals: 1



« Reply #2 on: 2012-02-03 02: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! Go get 'em!
Offline ReBirth

JGO Wizard
****

Posts: 1279
Medals: 19



« Reply #3 on: 2012-02-03 21: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.

Follow me, your mastah, on TWITTAH!
Offline JayTech

Jr. Member
**

Posts: 59
Medals: 1



« Reply #4 on: 2012-02-04 02: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

Full Member
**

Posts: 108
Medals: 2



« Reply #5 on: 2012-02-04 07: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

JGO Wizard
****

Posts: 1279
Medals: 19



« Reply #6 on: 2012-02-04 21: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.

1  
2  
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.

Follow me, your mastah, on TWITTAH!
Offline JayTech

Jr. Member
**

Posts: 59
Medals: 1



« Reply #7 on: 2012-02-06 12: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

JGO Wizard
****

Posts: 1279
Medals: 19



« Reply #8 on: 2012-02-07 21:44:26 »

Depends on how smooth you want. Kev's
http://www.java-gaming.org/topics/crusaders-of-yore/25654/msg/221831/view.html#msg221831
sprite maybe can give you a point.

Follow me, your mastah, on TWITTAH!
Offline sirlink99

JGO n00b
*

Posts: 4



« Reply #9 on: 2012-03-07 21:43:30 »

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

1  
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]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.063 seconds with 19 queries.