Small animation trouble...

Hi to all the avid developers/programmers out there :slight_smile:

I’m currently in the process of developing a game(in a 2D, top-down view) which involves the animation of a man walking around, and has the ability to pick up a sand bag.

With that off my chest, I have a variable to detect which key is pressed to change the direction which the character is facing, and therefore alters the image loaded, as there are animations for every direction he faces. (ie. 4 pictures for moving up, 4 for moving left… and you get the idea.)

What im querying is how I would go about animating the sand bag in his hands? I feel creating a bunch of new pictures for the sprite and have a boolean variable to detect whether he has a bag in his possesion is going to unnecessarily increase the size of the executable, as I would like to keep it small.

Is there a possible way to instead draw the image x pixels infront of the character?

Thanks in advance for any help.
Keep it Java :slight_smile:

You could make a new torso in the different directions, and draw that over the man, so it covers. The one where he’s holding a sandbag would be a little bigger? I don’t know, maybe that’s a bad solution. It only involves 4 new pictures though.

I was thinking having a horizontal image and a vertical image of the sandbag. When the appropriate keys are pushed(w,s,a and d are used to direct the man), a variable or two are altered and the sandbag is painted infront of the man’s chest. I’m just a bit clueless about doing this though… ???

Hmmm… or I could have a two animation sets for the man, one with the bag, and one without, and use a rotation transformation on the images… But not too sure about this either and how it may affect performance

[quote]Is there a possible way to instead draw the image x pixels infront of the character?
[/quote]
No reason why you can’t take the man’s X,Y location and print the sand bag relative to that.

With a graphics object, all draws overwrite what has already been drawn. So it is easy to overlay images, just watch what order you do the draw commands. If the image has transparency, then some amount of the previous image will show through. Are your images 100% opaque, or do you make the “background” area around the main art transparent?

Hi philfrei :slight_smile:

[quote]No reason why you can’t take the man’s X,Y location and print the sand bag relative to that.
[/quote]
I had this in mind but there are a few things I am confused about… The x,y co-ordinates provided, are they from the center of the mans image?

All the pictures I use are 100% opague fortunately. I dont intend to have any of the other images i may add any transparent either…

Images are drawn starting from the top left corner, so that corner’s coordinates are used.

If the center of the man’s image is what is provided when you do something like a getX() function, then during drawing, an offset of half the image’s width will usually be included to get the value of the left edge. But that all depends on how you programmed your image object. Are you using someone else’s code as a starting point?

Transparencies are easy to program, so I’d encourage their use. If you are on Windows, the standard tool Microsoft Photo Editor lets you set a given color to be transparent. If you load the image as a .png file, transparency data is preserved.

Ah ok i see, that sould be pretty simple to progem then :slight_smile: thank you :slight_smile:

I’ve taken a bit of time to reconsider my sprites and characters and have made new images however they do have some transparent bits. They are all of the .png format, but you say this won’t cause trouble in an animation since their transparency data is preserved?
By the way, I have analysed a few tutorials in order to get an idea of how to animate the images, and will be forming my own sort of way, which too will still add some sort of originality seeing as I just finished highschool and am new to this.

All seems to be going well, so far it’s aporximately 20% or so completed. I will post the code once it is done. :slight_smile: