Animation of my character doesn't work properly

Joifad

Member
The code I wrote is exactly like this

//Update Sprite
function PlayerAnimateSprite(){var _cardinalDirection = round(direction/90);
var _totalFrames = sprite_get_number(sprite_index) / 4;
image_index = localFrame + (_cardinalDirection * _totalFrames);
localFrame += sprite_get_speed(sprite_index) / FRAME_RATE;

//If animation would loop on the next game step
if (localFrame >= _totalFrames)
{
animationEnd = true;
localFrame -= _totalFrames;
}else animationEnd = false;

}

This code I wrote helps my character to move
My character has an animation running up, left, down
but when going to the right the animation does not move the character just slips

 
Last edited:

TsukaYuriko

☄️
Forum Staff
Moderator
For reference, directions in GameMaker work like this:

0 - right
90 - up
180 - left
270 - down

4-directional sprites should therefore be in that order when using the method you're using. Are your sprites' frames in that order?
 

Joifad

Member
For reference, directions in GameMaker work like this:

0 - right
90 - up
180 - left
270 - down

4-directional sprites should therefore be in that order when using the method you're using. Are your sprites' frames in that order?
yes the turn is right
 

TsukaYuriko

☄️
Forum Staff
Moderator
Then show us how the frames of your sprite are set up. Your code works for me - with a sprite that is organized properly - so the problem is the sprite.
 

TsukaYuriko

☄️
Forum Staff
Moderator
Please describe the issue in greater detail, including expected behavior and actual behavior, rather than paraphrasing them and especially don't summarize it as "doesn't work". That provides us with next to no useful information other than that something doesn't work the way you want it to work - and we know that, because otherwise you wouldn't be posting here - so we can't really use it to analyze the issue or find its cause. Help us help you. ;)

What does "doesn't work" stand for?
 

Joifad

Member
Please describe the issue in greater detail, including expected behavior and actual behavior, rather than paraphrasing them and especially don't summarize it as "doesn't work". That provides us with next to no useful information other than that something doesn't work the way you want it to work - and we know that, because otherwise you wouldn't be posting here - so we can't really use it to analyze the issue or find its cause. Help us help you. ;)

What does "doesn't work" stand for?
priority excuse me my english is not good i will try to explain as much as i can

This code I wrote helps my character to move
My character has an animation running up, left, down
but when going to the right the animation does not move the character just slips
 

Attachments

TsukaYuriko

☄️
Forum Staff
Moderator
So the animation is not playing at all and just showing the first frame when going to the right?

Is there any other code (that you haven't posted yet) that may be causing this? I copied your setup, sprite and code, and it works fine for me... so I'm pretty certain that what we've seen so far is not causing it.
 

Joifad

Member
So the animation is not playing at all and just showing the first frame when going to the right?

Is there any other code (that you haven't posted yet) that may be causing this? I copied your setup, sprite and code, and it works fine for me... so I'm pretty certain that what we've seen so far is not causing it.
yes the animation doesn't play at all when going to the right

I shot a 30 second video for you to understand better:
 

Nidoking

Member
A couple of things stand out:

You're setting image_index based on localFrame, then updating localFrame. That suggests that maybe you haven't thought about this process very much.

I don't see how you're setting direction, so maybe you've set it to 360 instead of 0 when you move right. Then you're always at the end of the animation, and who knows what the frame numbers will be doing?
 
Top