Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (568)
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 3473 times)
0 Members and 1 Guest are viewing this topic.
Offline JayTech

Junior Member


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 Member


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 Member


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 Member


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.

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.

Offline JayTech

Junior Member


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
http://www.java-gaming.org/topics/crusaders-of-yore/25654/msg/221831/view.html#msg221831
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 (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]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (40 views)
2014-09-24 16:13:29

Pippogeek (31 views)
2014-09-24 16:12:22

Pippogeek (21 views)
2014-09-24 16:12:06

Grunnt (47 views)
2014-09-23 14:38:19

radar3301 (29 views)
2014-09-21 23:33:17

BurntPizza (65 views)
2014-09-21 02:42:18

BurntPizza (37 views)
2014-09-21 01:30:30

moogie (43 views)
2014-09-21 00:26:15

UprightPath (53 views)
2014-09-20 20:14:06

BurntPizza (55 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!