• 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!

2 Behaviors for 1 Input?

D

Dezzick

Guest
New here and was looking for some pointers.
I've been trying sometime for an easier way to make the space bar play a different animation based on the direction my character is facing.

For instance, if facing right, I should execute an attack animation to the right.
If facing left, I should execute an attack animation to the left.

My issue is that I'm using sprite_index to call for different animations based on whatever key/direction I'm going, but now that I'd like to call for something different when using the space bar, I can't use these anymore as they're being used elsewhere.

An example:
Code:
if keyboard_check(ord("A"))
{
    x -= walkSpeed;
    image_speed = walkSpeed / 2;
    sprite_index = spr_character_left_walk;
}
else if (sprite_index = spr_character_left_walk)
{
    image_speed = walkSpeed / 3;
    sprite_index = spr_character_idle_left
I use this to move left and change character animations between walking and being idle.

Now if I try to do this for spacebar when facing either direction and refer back to the direction I'm facing using the sprite_index, it doesn't work very well at all.




I'm a bit beginner, so I appreciate the help.

Does anyone have a simple way they'd personally go about this that I can try?

Thanks!
 

Nidoking

Member
|| means or. So you would do
Code:
if (sprite_index == spr_character_left_walk || sprite_index == spr_character_idle_left)
However, I find it easier to have a variable called facing_left that I set in addition to the sprite_index when I change direction, so it's a single check regardless of how many sprites I have.
 
D

Dezzick

Guest
|| means or. So you would do
Code:
if (sprite_index == spr_character_left_walk || sprite_index == spr_character_idle_left)
However, I find it easier to have a variable called facing_left that I set in addition to the sprite_index when I change direction, so it's a single check regardless of how many sprites I have.
Lol are you kidding me! I can't believe I missed that haha! Beginner problems I guess. This is has already seemed to solve the main issue. The second smaller issue is just ensuring that upon the animation's completion, it returns to the idle animation.

You're the bomb! :)
 

MaxLos

Member
Lol are you kidding me! I can't believe I missed that haha! Beginner problems I guess. This is has already seemed to solve the main issue. The second smaller issue is just ensuring that upon the animation's completion, it returns to the idle animation.

You're the bomb! :)
You can use an animation end event and set your sprite index to the idle one from there
 
D

Dezzick

Guest
You can use an animation end event and set your sprite index to the idle one from there
Hey would you happen to have a better example of the animation end event being used other than the manual? I've been trying to implement it, but nothing seems to happen. Weird. I must be missing something. I'll have to continue trying later!
 

MaxLos

Member
Hey would you happen to have a better example of the animation end event being used other than the manual? I've been trying to implement it, but nothing seems to happen. Weird. I must be missing something. I'll have to continue trying later!
You could do something like this
Code:
//Animation End Event
if (sprite_index = spr_character_attack_left) or (sprite_index = spr_character_attack_right)
{
     if (sprite_index = spr_character_attack_left) sprite_index = spr_character_idle_left;
     else sprite_index = spr_character_idle_right;
     image_index = 0;
}
 
B

Betzalel feigenbaum

Guest
Code:
(Player movement controls (_ w _forward, _ D _ right, _B _ backwards, _A _left) I made the controls in my new game that I’m makeing
 
Top