Best practices for sprite animation.
#1
Posted 14 May 2012 - 11:18 AM
I have started today to add animation to my sprites. The way people ussually do this is just creating a sprite per animatoin and then changing sprite_index? I have seen some code around to allow having a sprite with all frames and build animations from there (changing image_index, etc... at runtime). Could anyone comment?
Thanks.
#2
Posted 14 May 2012 - 12:32 PM
If gravity is not equal to 0 (it gets set to 0 when George is on the ground)
change the sprite to spr_George_jump with subimage 0 and speed 0.25
Else
If hspeed is not equal to 0,
change the sprite to spr_George_walkwith subimage 0 and speed 0.25
Else
change the sprite to spr_George_stand with subimage 0 and speed 0.25
Then I play with image_xscale to change the facing direction.
If you put all the animations in a single sprite, you have to put code something like this in an
if (image_index == 6) image_index == 1; if (image_index == 12) image_index == 7; if (image_index == 18) image_index == 13; if (image_index == 24) image_index == 0;Because there's only one sprite (with a lot of subimages), it makes the resource list more compact, but I don't like this because 1) you can sort the sprites in groups anyway and 2) you lose the ability to label the different animations.
Edited by annihilator127, 14 May 2012 - 12:33 PM.
#3
Posted 14 May 2012 - 01:01 PM
#4
Posted 14 May 2012 - 01:50 PM
I myself use the separate sprite method. I think it's neater because you don't have to worry about managing different image_index domains; Game Maker does it for you. It works like this:
If gravity is not equal to 0 (it gets set to 0 when George is on the ground)
change the sprite to spr_George_jump with subimage 0 and speed 0.25
Else
If hspeed is not equal to 0,
change the sprite to spr_George_walkwith subimage 0 and speed 0.25
Else
change the sprite to spr_George_stand with subimage 0 and speed 0.25
Then I play with image_xscale to change the facing direction.
If you put all the animations in a single sprite, you have to put code something like this in anEnd Step event:
if (image_index == 6) image_index == 1; if (image_index == 12) image_index == 7; if (image_index == 18) image_index == 13; if (image_index == 24) image_index == 0;Because there's only one sprite (with a lot of subimages), it makes the resource list more compact, but I don't like this because 1) you can sort the sprites in groups anyway and 2) you lose the ability to label the different animations.
Yup, I got same feeling. Just wanted to know what people were using
Thanks for the info.
Edited by hexdump, 14 May 2012 - 01:51 PM.
#5
Posted 14 May 2012 - 03:34 PM
Also with this "normal" method, you can use the animation_end event to change sprites automatically at the end of the animation.
#6
Posted 14 May 2012 - 08:09 PM
Agreed with the above posters as well.
Also with this "normal" method, you can use the animation_end event to change sprites automatically at the end of the animation.
Thanks mate.
#7
Posted 14 May 2012 - 08:15 PM
if (image_index > 6 - image_speed) image_index == 1; if (image_index > 12 - image_speed) image_index == 7; //etc...
That will take care of any precision errors. I should also add, that all that can be avoided by simply making your sprites into separate ones and changing sprite index, as there is honestly no real reason not to! In many cases doing anything else is just complicating your life for the hell of it...
#8
Posted 15 May 2012 - 01:06 PM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











