• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

How to alter image position as if it is a 30FPS animation?

K

krugen

Guest
For example, you have a square that moves 1 pixel per frame and you set the fps to 30 when you imported the gif to GMS2. To run the gif would be "image_speed = 1;" and set it to zero when you hit the last frame, whatever that is.

Now, I don't want to waste time animate the whole thing in a different software and exported it as a gif for GMS2. I want to animate it directly and programmatically in GMS2.

To move, alter its (x,y), image_alpha, and so on.

What about FPS? I can't use image_speed because it is just a single frame of a square. Just set room_speed to 30?
 
S

spoonsinbunnies

Guest
if its a single frame there is no animation? if you mean move 1 frame per step as if it were animated you could just move the x or y per step. If you mean something else Im not sure, your wording here is a little wonky.
 
K

krugen

Guest
if its a single frame there is no animation? if you mean move 1 frame per step as if it were animated you could just move the x or y per step. If you mean something else Im not sure, your wording here is a little wonky.
Yea, but I wanna move it such that it is a 30 fps animation
 
S

spoonsinbunnies

Guest
room speed is how many times per second all the events are called so yes room speed is what you are looking for.
 
K

krugen

Guest
room speed is how many times per second all the events are called so yes room speed is what you are looking for.
I have another problem then. If the game is 60fps, how? What if I have all this other animation which runs at different fps?
 
S

spoonsinbunnies

Guest
that's just finding a ratio, and only updating at the ratio. If your room is at 60fps and you want a single object to run at 30 fps, you only update it every other step.
 
Your post is a little unclear. You talk about animation speed at 30 FPS, but also moving the position at 30 FPS, which are two different things.

If you want the thing to move at 30 FPS when your room is running at 60 FPS, you need to multiply all the places where you change the things position by 0.5.

If you want to generalise this for any room speed, you can calculate the number you need to multiply by, by taking the intended movement speed and dividing it by the room speed.

Create Event
Code:
// Original movement speed values;
// NOTE : This is just an example, you will probably have a different method
// of applying speed to your character. These values will just make the
// character move left and down continuously.
x_speed = 10;
y_speed = 10;

// Calculate adjustment factor
target_fps = 30;
actual_fps = room_speed;
scale_fps_amount = target_fps / actual_fps; // 30 / 60 in your case = 0.5
Step Event
Code:
// By multiplying the movement amount by the scale factor, the thing will
// move at the target speed as if it was running at the target fps.
x += x_speed * scale_fps_amount;
y += y_speed * scale_fps_amount;
You can apply this "scale_fps_amount" (as I have called it) to anything else you want to slow down relative to the actual room_speed. For example, if the original image_speed was 5, then multiplying it by the scale factor give you an image_speed of 2.5.
 
Top