Animation not working correctly

Hey guys,

I am trying to add animation for some characters that are not controlled directly by the player. I am using the following:

In create :

alarm[0] = room_speed * 0.1;
xx = x;
yy = y;


In step:

if (x > xx) {sprite_index = spr_enemyleft;}
if (x < xx) {sprite_index = spr_enemyright;}
if (y < yy) {sprite_index = spr_enemydown;}
if (y > yy) {sprite_index = spr_enemyup;}


Alarm[0]

alarm[0] = room_speed * 0.1;
xx = x;
yy = y;


It is working but the delay between sprite changes is much higher than I was hoping for meaning it doesn`t look all that good. What am I missing ? Frame rate is set to 60 so alarm should trigger well before it seems it does.

I am also open to other systems of animation if you guys have suggestions with the one mention that I really don`t need something complex as I am not planning a lot of animations per character.

Thank you in advance!
 
Thank you Simon. I didn`t know about this to be honest.

Unfortunately it doesn`t seem to work at all. When using these functions the animation doesn`t change.
 

Simon Gust

Member
Make sure you update the x and y position before you handle animation as xprevious and yprevious need to differ from x and y that step.
They are the same in the beginning of the step and are different the moment you change x and y that step. So animation comes after updating x and y.

Code:
if (x > xprevious) spr_enemyright;
if (x < xprevious) spr_enemyleft;
if (y > yprevious) spr_enemydown;
if (y < yprevious) spr_enemyup;
 
Got it to actually do something by adding the code in the end step but there is still the same delay in animation change as with the original code.
 

Simon Gust

Member
Got it to actually do something by adding the code in the end step but there is still the same delay in animation change as with the original code.
Can you elaborate on this delay? When I put this code in one of my objects it has no noticeable delay.
Is there some other code that may be hindering this, i.e. animation code, x and y related code?
 
First of all thank you for the follow up.

This is literally all the code on the object:


Create event:

Code:
pathgo = path_add();

Step event:

Code:
if (mp_grid_path (global.grid, pathgo, x,y,obj_goal.x, obj_goal.y,0))
{path_start(pathgo, 2, path_action_reverse, false);}

End Step event:

Code:
if (x > xprevious) {sprite_index = spr_enemyleft;}
if (x < xprevious) {sprite_index = spr_enemyright;}
if (y < yprevious) {sprite_index = spr_enemydown;}
if (y > yprevious) {sprite_index = spr_enemyup;}
The animation changes to face the direction it should about 1 second later (with the next update i guess).
PS: The animations themselves don`t seem the problem. I`ve changed to another set with the same effect.
 

Simon Gust

Member
If it takes a whole second then something is going very wrong. Because if your game runs at 60 fps, you have 60 updates per second.
 
Top