Weird movement animation

Xocrona

Member
Hi, so I'm knew in Game Maker desing (so Idk if this is a very newbie issue or I, as always, found a way to break the matrix :() and saw a tutorial 'bout making a walk animation. The code it's okay if you just use one sprite (with or without animation ;)), but here's the problem ... when I change between sprite (I made a slime to make my tests :D) it goes a little bit down for some reason and then goes back to normally when I change to the original sprite :confused:.

I have 2 sprites: base sprite and stand_by sprite. Base sprite (don't worry, I'm attaching the screenshots) is composed just by 1 frame and stand_by sprite by 2 frames: the base frame and an smashed slime. I've checked a lot of times, they're at the same level, same size, same everything (ignoring the fact that obviously smashed and base can't be equal :p). I thought "Hey, maybe your smashed slime is just a little bit down respect the base one", but in that case the base frame in stand_by sprite should be at the same level as the base sprite and that's not the case :oops:.

I think it might be something 'bout the room coordinates (that's making me suffer also bc it looks like 200, 200 in room coordinates it's not the same as 200, 200 coordinates in my instance bc idk). By the way, I'm leaving the code so you can tell me if maybe it's something that I modified or if I can do something inside to make it work like I want)

Thanks for reading, specially bc I'm not that good at speaking english so it may look like a kid it's writing. (I also tried to use emojis to make it less boring to read. I don't really use them very often so ... :potato:)

Create event for slime:

Code:
/// @descr Create event for slime_instance
//Creates a variable with 2 fields: stand and moving
enum states
    stand,
    moving
}

//State dafault value is stand
state = states.stand;

//Saves original x and y position
x_pos =x;
y_pos =y;

//Default value
x_from = x_pos;
y_from = y_pos;

//Default value
x_to = x_pos;
y_to= y_pos;

//These ones are to control slime animation
animacion_longitud=1;
animacion_tiempo=0;
Click event:

Code:
///@descr Right move with click
//Summons move script
move();
Move script
Code:
///@desc Right move

/*When it's summoned, it checks if the the slime is moving or not (to avoid moving 2 times with 2 clicks while moving.*/
if (state == states.stand){
    //Saves the current position
    x_from = x_pos;
    y_from = y_pos;
    
    //Place where the slime is moving
    x_to = x_pos + 200;
    y_to = y_pos;
    
    //Refresh the current position with the new one 
    x_pos = x_to;
    y_pos = y_to;
    
    //Change to moving state so Step event can make the animation
    state=states.moving;
}
And the one that it's the really mess: Step event for slime

Code:
///@descr Slime animation

//Goes on if slime is moving
if (state == states.moving){
    
    //Set slime's sprite to the stand_by animation
    sprite_index=slime_standBy;
    
    //New animation time
   animation_time += delta_time/1000000;
    
    //Unique var t to indicate that it has lapsed 1 frame sec
    var t = animation_time/animation_lenght;
    
    //If t >= 1 then animation time resets and we round t to 1 bc room time just count integers (quantity of frames)
    if (t >= 1){
        
        animation_time=0;
        t=1;
        //After this, movement has over so we set state in stand
        state=states_stand;
        
    }
    
    //_x and _y are the position where our slime should be after t secs knowing the origin and destiny
    var _x=lerp(x_from, x_to, t);
    var _y=lerp(y_from, y_to, t);
    
    //We move the slime into the new coordinates
    x=_x;
    y=_y;

//This part is the one that sets slime back to it base sprite. I know that this part is the problem bc when I don't set base sprite, it doesn't goes down
if(state==estado.espera){
    sprite_index=slime_base;
    }
Extra: I was including images, but it says that the files are way to big so I uploaded at lightshot
down here

https://prnt.sc/pd6jev
https://prnt.sc/pd6jd0
https://prnt.sc/pd6jja
https://prnt.sc/pd6k9v
 

Tthecreator

Your Creator!
What is the origin of your sprites? They should be the same. The origin is used to map the single point x/y coordinates of your object to a pixel on your sprite. Look for it in your sprite's settings.
 
Top