SOLVED My animations are jumping frames and when I "fix" it, it crashes the game.

D

DevilKap

Guest
I have an 8-directional animation system for my RPG, when I set the frames of the animation like this:
1600906360364.png
It works fine, but jumps/skips frames.

However, when I set it up like this:
1600906438747.png
It doesn't skip frames, but it crashes the game when I walk to the right (and only to the right) for an extended period.

My code for the animation is seen here:
1600906498427.png
Is there anything I'm doing wrong?
Keep in mind, this is meant to be an 8-directional animation for an RPG.
 

curato

Member
it is probably in one of those sprite functions, but it would be easier to break out the directions in separate sprites and switch them based on the direction. Then you can just use image_speed.
 

angelwire

Member
I've done something similar in my projects and I remember Gamemaker doing some weird things when the image_index reaches the frame count of the object's sprite_index. I'd recommend putting a debug message in the Animation End event to see if it's firing when you don't want it to.
 

TheouAegis

Member
Use a step counter. All it is is a variable that increments by one every step. You might want to loop it to avoid it ever maxing out.

stepcounter=++stepcounter & 255;

The set your image index when you change directions, doubled so it is set to the first frame of each animation.

image_index = direction div 45 * 2;

Then for every n steps, XOR the image_index by 1.

if stepcounter mod 8==0 {image_index^=1;}
 
D

DevilKap

Guest
Use a step counter. All it is is a variable that increments by one every step. You might want to loop it to avoid it ever maxing out.

stepcounter=++stepcounter & 255;

The set your image index when you change directions, doubled so it is set to the first frame of each animation.

image_index = direction div 45 * 2;

Then for every n steps, XOR the image_index by 1.

if stepcounter mod 8==0 {image_index^=1;}
I'm a noob at GML, where would I put this?
 

Chaser

Member
I would do what @curato says if you can't find the issue. seems like a lot of unnecessary checks and code when you could do it easier maybe. I will say that gamemaker sprites run in the background regardless of whether they are being used or not, so depending on what 'frame' is currently being used when the switch to another direction or state happens can seem like 'skipping' frames. So you should set the image_index to 0 BEFORE any changes so it starts the animation frame the first frame and not half way through. With your current code set up im not sure if you can do that though. Hope you can get your issue to work. :)
 
D

DevilKap

Guest
I would do what @curato says if you can't find the issue. seems like a lot of unnecessary checks and code when you could do it easier maybe. I will say that gamemaker sprites run in the background regardless of whether they are being used or not, so depending on what 'frame' is currently being used when the switch to another direction or state happens can seem like 'skipping' frames. So you should set the image_index to 0 BEFORE any changes so it starts the animation frame the first frame and not half way through. With your current code set up im not sure if you can do that though. Hope you can get your issue to work. :)
So I should set image_index to 0? because I don't know how I would format the code if the sprites are separate. I'm new to actual programming.
 

Chaser

Member
Well, to set an image index you would just say ‘image_index = 0’, and then change your ‘state’ to whatever your using, it’s impossible for me to know how to do it for the code you are using as I don’t think your using states. Image index will work on the sprite selected for said animation I can’t really make out by the images you have posted, I’m guessing you are using just one sprite sheet and creating the frames from that using code, in which case you will need to work out how to achieve this by going through your code and insert accordingly.:)
 
D

DevilKap

Guest
Well, to set an image index you would just say ‘image_index = 0’, and then change your ‘state’ to whatever your using, it’s impossible for me to know how to do it for the code you are using as I don’t think your using states. Image index will work on the sprite selected for said animation I can’t really make out by the images you have posted, I’m guessing you are using just one sprite sheet and creating the frames from that using code, in which case you will need to work out how to achieve this by going through your code and insert accordingly.:)
Should I try making multiple variables for each direction?
1601126600215.png
Also adding "image_index = 0" to the beginning of the script made it crash later than it did originally so that fixed the problem somewhat
 

Chaser

Member
The image there doesn’t show ‘image_index’, it shows image_speed. Image_speed is how fast the animation cycles, image_index is which frame of the cycle. Placing it in the create event will only action once at the very beginning each time that instance running the code is created. Is this your player object, or a controller object, I have no idea.
 
D

DevilKap

Guest
The image there doesn’t show ‘image_index’, it shows image_speed. Image_speed is how fast the animation cycles, image_index is which frame of the cycle. Placing it in the create event will only action once at the very beginning each time that instance running the code is created. Is this your player object, or a controller object, I have no idea.
That screenshot is the player object.
If you're wondering where image_index is, it's in a scripts called "PlayerAnimationSprite".
1601150632257.png
Edit: Here's what the step command in the player object looks like
1601151368972.png
 
Last edited by a moderator:

Chaser

Member
Your image_image is being controlled by the variables you have coded, so the crashing and experiences you are getting, looking at that code would be a good place to look to find out where the trouble lies. Is GameMaker giving you an error report? If so read what it says that should tell you where to find the problem, if it’s not giving you an error message and it’s just freezing, then that says to me there is a infinite loop going on in your code, so the code is the problem. Perhaps GameMaker is trying to run two scripts at the same time, that counter act each other?
I’m only a novice coder myself, so I wouldn’t be able to help you, my only advice to you is try it a simpler way of doing it. The way your doing seems pretty advance coding. Sorry I couldn’t be of any help.:)
 
D

DevilKap

Guest
Your image_image is being controlled by the variables you have coded, so the crashing and experiences you are getting, looking at that code would be a good place to look to find out where the trouble lies. Is GameMaker giving you an error report? If so read what it says that should tell you where to find the problem, if it’s not giving you an error message and it’s just freezing, then that says to me there is a infinite loop going on in your code, so the code is the problem. Perhaps GameMaker is trying to run two scripts at the same time, that counter act each other?
I’m only a novice coder myself, so I wouldn’t be able to help you, my only advice to you is try it a simpler way of doing it. The way your doing seems pretty advance coding. Sorry I couldn’t be of any help.:)
It's alright, I managed to find a prim and proper tutorial on this exact thing. Thanks for your help though.
 
Top