GMS 2 Having Trouble Moving Sprite Animation Frames along X and Y axis

N

Naeem Sanders

Guest
Hello all,

Haven't used game maker long but I love it so far! My current issue is that I have an Action_Selector Obj with an attack option, when the user key_check_pressed(ord("A")) on that selection I want to hide the Idle_Character_Obj and un-hide the jump_to_target animation then wait at idle for another command when the animation ends.

I want to make sure the frames in the jump animation are in the correct spots on the x and y axis to make the jump look like and actual jump forward, not sure if I need multiple objects with each frame and iterate through those but there seems like there's a better way.

I've tried to play with the object at x and y but can't figure out how to have each frame set at different points on the x and y axis yet.

Any advice or reference on this would be greatly appreciated!
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
I'm not sure I see the issue here... Generally you'd have different sprite animations for each movement type and then switch between them depending on the player state. So if the player is in a jumping state you'd switch to the jumping sprite and just let the animation run as you move the instance. The animation (sprite) origin will always be at the player x/y position and so should move with the player object as it jumps... Do you have an image or a moc-up of the problem you're having? Might help us better understand the situation...
 
N

Naeem Sanders

Guest
I'm not sure I see the issue here... Generally you'd have different sprite animations for each movement type and then switch between them depending on the player state. So if the player is in a jumping state you'd switch to the jumping sprite and just let the animation run as you move the instance. The animation (sprite) origin will always be at the player x/y position and so should move with the player object as it jumps... Do you have an image or a moc-up of the problem you're having? Might help us better understand the situation...
Here is the animation I want to execute when a is pressed on the selector object. When I start the code

Code:
//create event
jump_forward = Btl_Jump_Frwd
Code:
//step event
if (keyboard_check_pressed(ord("A"))) {
      jump_forward.visible = true
      Charater_Idle.visible = false
}
however when I at the start when I make the jump_foward sprite visble the animation runs in the spot it was placed in the room and doesn't move.

Let me know if you need anymore context from me to identify the problem and thank you for responding!
 

Attachments

Last edited by a moderator:

NightFrost

Member
Your code suggests you have multiple objects for different player states... that adds an unnecessary layer of complexity to the thing. You should look into state machines (which despite the name are a way of structuring your code) which offer an easy method to do all that in a single object.
 

TheouAegis

Member
You have no vector dynamics in your code at all. You need to apply vertical and horizontal vectors.

if keyboard_check_pressed(ord("A")) {
sprite_index = whatever the heck your jumping sprite is
vspeed = -4;
hspeed = 2;
gravity = 1/8;
 
N

Naeem Sanders

Guest
Your code suggests you have multiple objects for different player states... that adds an unnecessary layer of complexity to the thing. You should look into state machines (which despite the name are a way of structuring your code) which offer an easy method to do all that in a single object.
Thanks for the response and I'll look into state machines! Would you suggest keeping all player animations within one object and accessing just the needed frames?
 
N

Naeem Sanders

Guest
You have no vector dynamics in your code at all. You need to apply vertical and horizontal vectors.

if keyboard_check_pressed(ord("A")) {
sprite_index = whatever the heck your jumping sprite is
vspeed = -4;
hspeed = 2;
gravity = 1/8;
Thank you for the response! Yeah I'm still new but I've seen and worked on a few tutorials. I'll try this and see if this gets me the desired result!
 

NightFrost

Member
Would you suggest keeping all player animations within one object and accessing just the needed frames?
Yes, that's the most common way of doing it. You can tell be the present state of the state machine what sprite you need to use, and if necessary further refine the use with alarms or counters. If animations is the main reason to split player into multiple objects, a state machine is a simpler solution than trying to sync up all those.
 
N

Naeem Sanders

Guest
Yes, that's the most common way of doing it. You can tell be the present state of the state machine what sprite you need to use, and if necessary further refine the use with alarms or counters. If animations is the main reason to split player into multiple objects, a state machine is a simpler solution than trying to sync up all those.
Thank you! I've been looking into state machines and it looks like the solution I was looking for!
 
Top