Multiple Animations in one sprite

Q

Qazwurtle

Guest
Hi, so I have an object that when he moves left and right a walking animation plays
and when the sprite flips when he turns around. I have all the sprites for the animation just together
in the sprite itself, so I was wondering, if I want something to have multiple animations, how do I go
about doing that, thanks

-Will
 
K

Kululu17

Guest
You will probably want to set up some additional parameters, since at some point I assume you will want to change more than just the animation. I usually set up a variable for "direction facing", and then use "sprite_index" to switch the animation.

e.g.
//insert whatever you use to control the character and make them move right -- keyboard_check_pressed for example
Direction_Facing = "Right";
sprite_index = SPR_Hero_Right_Walk;

//command for left movement...
Direction_Facing = "Left";
sprite_index = SPR_Hero_Left_Walk;

You can do the same for up, down, etc if you have separate animations...

You don't need the Direction_Facing now, but it will probably be useful later...
 
Q

Qazwurtle

Guest
You will probably want to set up some additional parameters, since at some point I assume you will want to change more than just the animation. I usually set up a variable for "direction facing", and then use "sprite_index" to switch the animation.

e.g.
//insert whatever you use to control the character and make them move right -- keyboard_check_pressed for example
Direction_Facing = "Right";
sprite_index = SPR_Hero_Right_Walk;

//command for left movement...
Direction_Facing = "Left";
sprite_index = SPR_Hero_Left_Walk;

You can do the same for up, down, etc if you have separate animations...

You don't need the Direction_Facing now, but it will probably be useful later...

Thanks for the reply, but my main problem is, how do I store all of the separate animations into the sprite, without running through them all, thanks
 

Roderick

Member
Thanks for the reply, but my main problem is, how do I store all of the separate animations into the sprite, without running through them all, thanks
You don't. You make one sprite for each animation, and then you use the sprite_index variable to change the sprite that your object is using.

In case this is the source of the confusion: An object is NOT a sprite, and vice versa. The sprite is just the picture and/or animation. The object is the code that interacts with other things in your game.
 
K

Kululu17

Guest
Hi,

You can run only certain frames of the animation if you want to put all the frames in the same sprite, but I find it's easier to read and debug if you break the sprites into blocks (SPR_Walk_Right = just the 4 frames, walking to the right, etc). Otherwise you have to know that frames 0-3 are for walking right, 4-7 are left, 8-12 are attacking right, etc. But you can do it that way with the image_index command. I haven't done it that way in any of my games, so I will defer to other members regarding a code example.
 
Q

Qazwurtle

Guest
Thanks all, I just realised how to properly use sprite_index, I had all the sub-sprites into one sprite and was trying to do it from there,
thank you very much :) Problem solved
 
Top