multi stage jump?

P

piksil_demon

Guest
hi ill try to keep this simple.
in my game i have 4 parts of animation for my jump.
stage 1 is the crouch, and jump up.
stage 2 is to transition the characters cape and she starts falling
stage 3 is the falling animation
stage 4 is a landing animation.

with that said i have 3 questions-

how do i let the game know how to transition to the next stage?
how do i make stage 3's length variable?
can you please provide a sample code that i can adapt into my game?

thank you ^_^
 
Last edited by a moderator:
A

AnimusRex

Guest
I'd do something like
if vsp < 0
spr_index = spr_jumpprep
if vsp < -2
spr_index = spr_transition

etc.

image_speed = 0.5 can make the animation last longer, I'd just make it so whenever they're travelling down, you draw the falling sprite. It really depends on how you have your platforming code set up.
 
W

Wild_West

Guest
hi ill try to keep this simple.
in my game i have 4 parts of animation for my jump.
stage 1 is the crouch, and jump up.
stage 2 is to transition the characters cape and she starts falling
stage 3 is the falling animation
stage 4 is a landing animation.

with that said i have 3 questions-

how do i let the game know how to transition to the next stage?
how do i make stage 3's length variable?
can you please provide a sample code that i can adapt into my game?

thank you ^_^

So your looking to change from one sprite to anther to play out a full animation right?
Are the frames for the animation all their own sprite? If so you can make a switch statement in the animation end event, that's the simplest way I'd do it.
The only way really I'm no expert lol

also for the length, I'd just duplicate some of the frames in the animation and set the image speed low so it plays longer.

I hope that's what you were getting at

In Animation End Event

switch(sprite_index)
{
case character_jump : sprite_index = character_in_air; break;

case character_in_air : sprite_index = character_falling; break;

case character_falling : sprite_index = character_landing; break;

case character_landing : sprite_index = character_idle; break;
}

I use that for all my character's animation changes, works great
 
P

piksil_demon

Guest
So your looking to change from one sprite to anther to play out a full animation right?
Are the frames for the animation all their own sprite? If so you can make a switch statement in the animation end event, that's the simplest way I'd do it.
The only way really I'm no expert lol

also for the length, I'd just duplicate some of the frames in the animation and set the image speed low so it plays longer.

I hope that's what you were getting at

In Animation End Event

switch(sprite_index)
{
case character_jump : sprite_index = character_in_air; break;

case character_in_air : sprite_index = character_falling; break;

case character_falling : sprite_index = character_landing; break;

case character_landing : sprite_index = character_idle; break;
}

I use that for all my character's animation changes, works great
no, thier each their own sprite. the problem is that the falling animation could be 3 frames, or 100 (hypothetically) so i just cant duplicate them,
i need a way to detect when to enter them, loop them, and detect when to exit them
 
Last edited by a moderator:
P

piksil_demon

Guest
I'd do something like
if vsp < 0
spr_index = spr_jumpprep
if vsp < -2
spr_index = spr_transition

etc.

image_speed = 0.5 can make the animation last longer, I'd just make it so whenever they're travelling down, you draw the falling sprite. It really depends on how you have your platforming code set up.
i was thinking along the same idea, it may work
 

TheouAegis

Member
Ignore the code aspect of the FSM article.

Look around you. Is there a light switch near you? Flip the light switch. Did the lights toggle on/off? Now flip the light switch back the other way. Did the lights toggle off/on? There, you just used a finite state machine.

Do you have a smartphone? Turn it on. Swipe your screen or whatever you need to do to unlock it. Click on the CALL button. I won't go on any further than that - you just used a finite state machine.

Have you ever cooked something following a recipe? There, you just used a finite state machine.
 

Fanatrick

Member
Like TheouAegis explained, you can basically just use switch statement with a state variable that would define in what state the object is currently in, so it only processes the code in its current state.
You can also use a substate variable that defines a secondary action inside the current state. For example, if the character is in "move" state, check for keystrokes for jump, in case it's pressed change the state variable to "jump". In "jump" state define a substate depending on if the player is in "takeoff", "rise" or "fall" state and then change the sprite accordingly. I hope the explanation is acceptable D:
 
P

piksil_demon

Guest
Ignore the code aspect of the FSM article.

Look around you. Is there a light switch near you? Flip the light switch. Did the lights toggle on/off? Now flip the light switch back the other way. Did the lights toggle off/on? There, you just used a finite state machine.

Do you have a smartphone? Turn it on. Swipe your screen or whatever you need to do to unlock it. Click on the CALL button. I won't go on any further than that - you just used a finite state machine.

Have you ever cooked something following a recipe? There, you just used a finite state machine.
Like TheouAegis explained, you can basically just use switch statement with a state variable that would define in what state the object is currently in, so it only processes the code in its current state.
You can also use a substate variable that defines a secondary action inside the current state. For example, if the character is in "move" state, check for keystrokes for jump, in case it's pressed change the state variable to "jump". In "jump" state define a substate depending on if the player is in "takeoff", "rise" or "fall" state and then change the sprite accordingly. I hope the explanation is acceptable D:
Neither of theses TELL me how to do this. I know how finite state machines work in theory but i dont know how to code them. I have close to no coding expirence. all the philosophical **** in the world isnt going to tell me how to use it. Like i said- i need sample code
 
C

ConsolCWBY

Guest
Neither of theses TELL me how to do this. I know how finite state machines work in theory but i dont know how to code them. I have close to no coding expirence. all the philosophical **** in the world isnt going to tell me how to use it. Like i said- i need sample code
Here.
 
Top