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!
We are new to GMS2 with my friend. We are making a project together and we cannot find a timer command.
We used Scratch earlier on and there was a "Wait _ Second" command.
Now our character is going to jump but the 1st 2nd 3rd and 4th sprites are preparing to jump sprites
so when we hit jump button it should do the preparing animations first.
Then go up and do the jump animation at the same time (5,6,7 and 8th sprites) until hitting the ground.
After that he should touch the ground and do the 9,10,11 and 12th sprites
Also first 4 sprites are going to be faster to jump faster and be more fluid
on-air sprites should keep going until hitting the ground
and hitting ground animations when hitting ground.
There is no wait command. Time passing implies you let steps execute. Waiting during some amount of steps implies your code uses conditional logic to execute or not execute some bit of code until the desired amount of time and steps has passed.
If you need something time related, alarms are your friends.
When timing with sprites, Animation End event.
Split this animation into 3 sprites. jump_begin, jump, jump_end.
Hit jump -> set jump_begin -> when animation_end -> set jump -> do jumping -> when animation_end -> set jump_end -> switch to idle
Edit: I totally forgot about broadcast. This makes it even easier without splitting the sprite. Thanks @EvanSki
In other languages, it is easy to set up when stuff will happen. For example : repeat(5) { x += 1 wait(1) } // This makes you move 5 steps every second.
I'm actually the designer, my friend is coding.
He says alarms doesn't work and he couldn't find broadcast messages. Do you have any code line
that can help us out
If you need something time related, alarms are your friends.
When timing with sprites, Animation End event.
Split this animation into 3 sprites. jump_begin, jump, jump_end.
Hit jump -> set jump_begin -> when animation_end -> set jump -> do jumping -> when animation_end -> set jump_end -> switch to idle
Edit: I totally forgot about broadcast. This makes it even easier without splitting the sprite. Thanks @EvanSki
My friend says walking is a loop it goes for ever if he do the same for
jumping animations it will keep repeating he says it would be great if he would be able to add time
i believe he doesn't know how to end animation and asks what is "animation_end"
Do you have any code line that can help us?
I'm actually the designer, my friend is coding.
He says alarms doesn't work and he couldn't find broadcast messages. Do you have any code line
that can help us out
broadcast messages are in the sprite resource
then in the player object when the sprite does the broadcast message
the broadcast message event will fire
Just for double checking: You are using Gamemaker Studio v2.3+ and not an older GM2 version? Because broadcast messages is something recently.
Also about broadcast messages: Manual
Edit: Wait, thread tag says GMS2. So no such thing. Was animation end pre GMS2.3?
Just for double checking: You are using Gamemaker Studio v2.3+ and not an older GM2 version? Because broadcast messages is something recently.
Also about broadcast messages: Manual
Edit: Wait, thread tag says GMS2. So no such thing. Was animation end pre GMS2.3?
Just for double checking: You are using Gamemaker Studio v2.3+ and not an older GM2 version? Because broadcast messages is something recently.
Also about broadcast messages: Manual
Edit: Wait, thread tag says GMS2. So no such thing. Was animation end pre GMS2.3?
Animation end event: an event that triggers when an animation ends.
alarms (and if he says alarms won't work I'd like to hear why other than they're a bit cumbersome)
The step event and conditional logic. Game Maker gives you access to what sprite is being used and what frame is playing; that alone gives you all the information needed to check on all of this.
The step event and a custom timer solution (each step is 1/room_speed seconds long)
and, while I strongly advocate against it, separate objects for each state. Technically an option, a horrible option given you're likely going to be using some of the other strategies anyway.
Do people actually have a need for this enough that I should make an extension for it? I'm happy to make an extension for desktop platforms, but I would prefer a real use case presented to me where it would be useful before taking the time to do it.
My friend says walking is a loop it goes for ever if he do the same for
jumping animations it will keep repeating he says it would be great if he would be able to add time
i believe he doesn't know how to end animation and asks what is "animation_end"
Do you have any code line that can help us?
Animation End and Broadcast Messages are events. You'll find them in "Add Event" -> "Other".
Walking is not a loop that goes forever, strictly speaking. If this is the case, you can't do anything besides walking The sprite might be a loop that goes forever while walking.
Lets look at this:
Also first 4 sprites are going to be faster to jump faster and be more fluid
on-air sprites should keep going until hitting the ground
and hitting ground animations when hitting ground.
I translate it like this:
Is a fixed length. Once the 4 sprites are done, you go airborn
Is a variable length. It's a loop. Jumping to the same height, jumping a platform down or up have all different lengths. We don't "know" how long the sprite has to loop
Is again a fixed length. You hit the ground, it plays the last 4 sprites.
I tried it with broadcast and didn't like it in this case. It's possible, but I went with 3 different sprites and Animation End event. The "work/setup" time are equal.
Broadcast Messages:
Pro:
Dealing with one sprite
no overlook with collision masks
Cons:
(personal) dealing with strings
change sprite during development means doing the setup again
Animation End:
Pro:
Sprites can easely be changed, no new setup needed
Nothing major and it comes down to your personal taste.
But how to do that? Well, I would go with a state machine. The state machines eliminates the "walk loop" thought. Walk is a endless loop as long as you are in a "walking" state. Certain condition lets you escape the walk state and move to a different state.
Because I played around with broadcast messages, I have some code examples for you. It uses the state machine, state transistion and Animation End event. It's an example, so the player can't do much.
//execute state each step
switch(state)
{
case player_state.idle:
{
//I'm useless and do nothing
break;
}
case player_state.walk:
{
//I'm doing the walk each step
//code
break;
}
case player_state.jump:
{
//we are in substate air; do the actual jumping
if(sprite_index == spr_player_jump_air)
{
vsp += GRAVITY;
//collide with ground?
if(place_meeting(x, y + vsp, obj_wall))
{
vsp = 0;
image_index = 0;
sprite_index = spr_player_jump_land;
}
y += vsp
}
break;
}
}
//state transitions; conditions; set information for next state
switch(state)
{
case player_state.idle:
{
if(PLAYER_KEY_HORIZ != 0)
{
image_speed = 1;
image_index = 0;
sprite_index = spr_player_walk;
state = player_state.walk;
}
if(PLAYER_KEY_JUMP)
{
image_speed = 1;
image_index = 0;
sprite_index = spr_player_jump_prep;
vsp = JUMPSTRENGTH;
state = player_state.jump;
}
break;
}
case player_state.walk:
{
if(PLAYER_KEY_HORIZ == 0)
{
image_speed = 0;
image_index = 0;
vsp = 0;
hsp = 0;
state = player_state.idle;
}
if(PLAYER_KEY_JUMP)
{
image_speed = 1;
image_index = 0;
sprite_index = spr_player_jump_prep;
vsp = JUMPSTRENGTH;
state = player_state.jump;
}
break;
}
case player_state.jump:
{
//handled in animation end
break;
}
}
Animation End Event
GML:
//sub states for jump
switch(sprite_index)
{
case spr_player_jump_prep:
{
image_index = 0;
sprite_index = spr_player_jump_air;
break;
}
case spr_player_jump_air:
{
//does nothing, sub state changes in step due ground collision
break;
}
case spr_player_jump_land:
{
//we landed, the animation ended, so set the next state
image_speed = 0;
image_index = 0;
sprite_index = spr_player_walk;
state = player_state.idle;
break;
}
}
I used some technics with macros and enums. Enums indicate the different states. Macros are used for static variables or small functions. I know later, that this is only a readable value and nothing, that should change by the code.
Also, I didn't use scripts/functions for the states. I usually do that to put the state execution code AND state transition code into one place. So now we have two switch statements in the step event. One is the state execution, the code that might play every step and one is the state transition, that only plays once, when the conditions are met and move the player into a different state. It also sets up some information - once. Sub states (the jumping animation in total) are not in the state transistion. I handle them as state execution. How you lay out the code in the end is your design.
So but how does it look in the end?
White is the walk/idle animation. If I hit a movement key, they jiggle. If I don't hit a key, the animation stops. It's the same sprite.
The numbers on the colored sprites indicate the current sprite frame.
Green is the jump preperation sprite. As soon as I hit the jump key, it starts playing.
Yellow is the jump air sprite. It loops as long as you are airborn. You see, that it went from 4 back to 1.
Red is the land sprite. Once landing is done, we go back to the walk sprite /idle state and then maybe right into the walk state (see how the white sprite stops after landing OR moves?).
The gif is choppy due the convertion. Also I'm not an artist, so pay the simple visualization no attention.
It doesn't involve real movement. The code is just a basic idea.
Thanks for your answers!
Vusur solved the problem yet i cant close this post
Because i want little more help. My character can jump and walk
but also can walk when jumping this interrupts jumping animation plus
it hangs on air after walking while jumping and doesnt fall back.
Animation End and Broadcast Messages are events. You'll find them in "Add Event" -> "Other".
Walking is not a loop that goes forever, strictly speaking. If this is the case, you can't do anything besides walking The sprite might be a loop that goes forever while walking.
Lets look at this:
Also first 4 sprites are going to be faster to jump faster and be more fluid
on-air sprites should keep going until hitting the ground
and hitting ground animations when hitting ground.
I translate it like this:
Is a fixed length. Once the 4 sprites are done, you go airborn
Is a variable length. It's a loop. Jumping to the same height, jumping a platform down or up have all different lengths. We don't "know" how long the sprite has to loop
Is again a fixed length. You hit the ground, it plays the last 4 sprites.
I tried it with broadcast and didn't like it in this case. It's possible, but I went with 3 different sprites and Animation End event. The "work/setup" time are equal.
Broadcast Messages:
Pro:
Dealing with one sprite
no overlook with collision masks
Cons:
(personal) dealing with strings
change sprite during development means doing the setup again
Animation End:
Pro:
Sprites can easely be changed, no new setup needed
Nothing major and it comes down to your personal taste.
But how to do that? Well, I would go with a state machine. The state machines eliminates the "walk loop" thought. Walk is a endless loop as long as you are in a "walking" state. Certain condition lets you escape the walk state and move to a different state.
Because I played around with broadcast messages, I have some code examples for you. It uses the state machine, state transistion and Animation End event. It's an example, so the player can't do much.
//execute state each step
switch(state)
{
case player_state.idle:
{
//I'm useless and do nothing
break;
}
case player_state.walk:
{
//I'm doing the walk each step
//code
break;
}
case player_state.jump:
{
//we are in substate air; do the actual jumping
if(sprite_index == spr_player_jump_air)
{
vsp += GRAVITY;
//collide with ground?
if(place_meeting(x, y + vsp, obj_wall))
{
vsp = 0;
image_index = 0;
sprite_index = spr_player_jump_land;
}
y += vsp
}
break;
}
}
//state transitions; conditions; set information for next state
switch(state)
{
case player_state.idle:
{
if(PLAYER_KEY_HORIZ != 0)
{
image_speed = 1;
image_index = 0;
sprite_index = spr_player_walk;
state = player_state.walk;
}
if(PLAYER_KEY_JUMP)
{
image_speed = 1;
image_index = 0;
sprite_index = spr_player_jump_prep;
vsp = JUMPSTRENGTH;
state = player_state.jump;
}
break;
}
case player_state.walk:
{
if(PLAYER_KEY_HORIZ == 0)
{
image_speed = 0;
image_index = 0;
vsp = 0;
hsp = 0;
state = player_state.idle;
}
if(PLAYER_KEY_JUMP)
{
image_speed = 1;
image_index = 0;
sprite_index = spr_player_jump_prep;
vsp = JUMPSTRENGTH;
state = player_state.jump;
}
break;
}
case player_state.jump:
{
//handled in animation end
break;
}
}
Animation End Event
GML:
//sub states for jump
switch(sprite_index)
{
case spr_player_jump_prep:
{
image_index = 0;
sprite_index = spr_player_jump_air;
break;
}
case spr_player_jump_air:
{
//does nothing, sub state changes in step due ground collision
break;
}
case spr_player_jump_land:
{
//we landed, the animation ended, so set the next state
image_speed = 0;
image_index = 0;
sprite_index = spr_player_walk;
state = player_state.idle;
break;
}
}
I used some technics with macros and enums. Enums indicate the different states. Macros are used for static variables or small functions. I know later, that this is only a readable value and nothing, that should change by the code.
Also, I didn't use scripts/functions for the states. I usually do that to put the state execution code AND state transition code into one place. So now we have two switch statements in the step event. One is the state execution, the code that might play every step and one is the state transition, that only plays once, when the conditions are met and move the player into a different state. It also sets up some information - once. Sub states (the jumping animation in total) are not in the state transistion. I handle them as state execution. How you lay out the code in the end is your design.
White is the walk/idle animation. If I hit a movement key, they jiggle. If I don't hit a key, the animation stops. It's the same sprite.
The numbers on the colored sprites indicate the current sprite frame.
Green is the jump preperation sprite. As soon as I hit the jump key, it starts playing.
Yellow is the jump air sprite. It loops as long as you are airborn. You see, that it went from 4 back to 1.
Red is the land sprite. Once landing is done, we go back to the walk sprite /idle state and then maybe right into the walk state (see how the white sprite stops after landing OR moves?).
The gif is choppy due the convertion. Also I'm not an artist, so pay the simple visualization no attention.
It doesn't involve real movement. The code is just a basic idea.
No. This is a definition problem. You can't walk while jumping. Those are distinct states. Walking is usually defined as "I'm on the ground and move left/right (press left/right key)".
What you probably mean is move while airborn. See that it doesn't met the "I'm on the ground" definition?
With that in mind, your walk state gets code for moving left/right AND your jump state gets code for moving left/right. Moving left/right does NOT trigger a state change. The functionality/code is pretty much the same, the meaning behind it isn't.
It looks like you are escaping the jump state as soon as you move midair (jump state -> walk state). You don't want that. The only way to escape the jump condition is, when you are back on the ground AND the last animation has played. Not when you move/hit movement keys. That it hangs midair also means, that gravitiy with vsp has no meaning in your walk state. You would have the same problem, when you walk off an edge.
The code provided was a pure skeleton. There was no real movement or collisions involved. It was just a showcase, how you could do it with a state machine. Tailored specificly for the case showing the sprite changes and jump.
Maybe we scratch the whole 3-part-animation stuff, do a simple jump and get some basics first? Movement, collisions with ground/objects and so on. Yoyo games has some good tutorials. Even a platformer one. After that, state machines make more sense and then polishing. Building upwards instead of downwards.
What does movement in a platformer mean, how can you express different movements in code? walk, jump, fall, moving against the wall (collisions) and so on
How can I express 1. as a state machine (many tuts with state machines as a general concept. State machines are not bound to GMS)
polishing movements
Because 3-part-animation-as-sub-state needs the knowledge of state machine. And state machine needs the knowledge of basic movement and what the char should can do. Step by step is better than going into details first.
1. The walking animation instead of idle when he falls after jump
2. Walks without doing the walking animation if you press Jump and Walk buttons at the same time
3. The walking animation even though he actually doesn't walk if you press Right and Left Walk buttons at the same time
4. Another jump when you are already on air if you press Jump button again and that keeps going untill you go out of the frame.
5. Walks on the air like there is an invisible ground.
We have 5 glitches just in the first 2 moves where did i do wrong. This is too hard. We are watching videos and trying what you guys are saying but glitches keeps happening
1. The walking animation instead of idle when he falls after jump
2. Walks without doing the walking animation if you press Jump and Walk buttons at the same time
3. The walking animation even though he actually doesn't walk if you press Right and Left Walk buttons at the same time
4. Another jump when you are already on air if you press Jump button again and that keeps going untill you go out of the frame.
5. Walks on the air like there is an invisible ground.
We have 5 glitches just in the first 2 moves where did i do wrong. This is too hard. We are watching videos and trying what you guys are saying but glitches keeps happening
//execute state each step
switch(state)
{
case player_state.idle:
{
//I'm useless and do nothing
break;
}
case player_state.walk:
{
//I'm doing the walk each step
//code
break;
}
case player_state.jump:
{
//we are in substate air; do the actual jumping
if(sprite_index == player_jump)
{
vsp += GRAVITY;
//collide with ground?
if(place_meeting(x, y + vsp, wall))
{
vsp = 0;
image_index = 0;
sprite_index = player_jump_land;
}
y += vsp
}
break;
}
}
if(PLAYER_KEY_LEFT)
{
x=x-5;
sprite_index = player_walk
image_speed = 0.1;
image_xscale = -0.7;
image_yscale = 0.7;
}
if(PLAYER_KEY_RIGHT)
{
x=x+5;
sprite_index = player_walk
image_speed = 0.1;
image_xscale = 0.7;
image_yscale = 0.7;
}
switch(state)
{
case player_state.idle:
if(PLAYER_KEY_JUMP)
{
image_speed = 1;
image_index = 0;
sprite_index = player_jump_prep;
vsp = JUMPSTRENGTH;
state = player_state.jump;
}
break;
}
{
}
if(PLAYER_KEY_JUMP)
{
image_speed = 1;
image_index = 0;
sprite_index = player_jump_prep;
vsp = JUMPSTRENGTH;
state = player_state.jump;
}
{
}
Animation End:
(Added walk codes for here too as far as i understood from codes u sent)
Code:
switch(sprite_index)
{
case player_jump_prep:
{
image_index = 0;
sprite_index = player_jump;
break;
}
case player_jump:
{
break;
}
case player_jump_land:
{
image_speed = 0;
image_index = 0;
sprite_index = player_walk;
state = player_state.idle;
break;
}
case player_walk:
{
image_speed = 0;
image_index = 0;
sprite_index = player_idle;
state = player_state.idle;
break;
}
}
And thats it. I didn't add more then that
How can i have bugs that much just after a walk code?
As i said earlier im the designer and don't understand
much and my friend is trying his own ways and getting
weirder glitches
We want to add tilting in the air, dashing, parrying, melee attack, ranged attack, more then 5 types of enemies and their attacks and AI, Bosses
But we get stuck at the first steps ...
Well, copy pasting without understanding won't work. That's why I said, we go some steps back. I added some comments in the code
GML:
//execute state each step
switch(state)
{
case player_state.idle:
{
//I'm useless and do nothing
break;
}
case player_state.walk:
{
//I'm doing the walk each step
//code
//**************************************************************************
//why is here no code? I even commented, that walk code belongs here
//**************************************************************************
break;
}
case player_state.jump:
{
//we are in substate air; do the actual jumping
if(sprite_index == player_jump)
{
vsp += GRAVITY;
//collide with ground?
if(place_meeting(x, y + vsp, wall))
{
vsp = 0;
image_index = 0;
sprite_index = player_jump_land;
}
y += vsp
}
break;
}
}
//*************************************************************************************
//why is this outside of the state machine? It now doesn't belong to walk nor jump
//*************************************************************************************
if(PLAYER_KEY_LEFT)
{
x=x-5; //THIS is movement code. it goes in state execution
sprite_index = player_walk //* this is a single assignment (doesn't need to be set each step), this goes in state transition
image_speed = 0.1; //* same
image_xscale = -0.7; // same
image_yscale = 0.7; //same
}
if(PLAYER_KEY_RIGHT)
{
x=x+5;
sprite_index = player_walk
image_speed = 0.1;
image_xscale = 0.7;
image_yscale = 0.7;
}
//...snip
Same with the animation end. Animation end is a switcher for the substates jump. Not for walking. Walking has nothing to do with animation end.
At this point, I give you guys some links. Yoyo tutorials - There is even a platformer tutorial. SamSpades Youtube - A lot of usueful stuff, once the basics are down. There is even stuff with state machines and how you refactoring your code.
Scratch this approach and start with the basics. Adding new code to the code provided is not a good idea. It needs some knowledge.
I have no knowledge i stopped making sprites and tryna do codes even tho i have no idea about codding
also i put the walk code in the state thingy and my charecter now can't move :/ im dumb