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

Switch Attacks

T

Tanner021

Guest
Hey all,

I am having trouble figuring out how I will be able to switch between my sprite_index. I have been trying to make it so that when you attack the first time(button_c) you will throw a right punch... when you attack a second time the sprite_index will be the left punch. I would like it to be back and forth like that, but it's only been sticking to one sprite every time I perform the action. It seems obvious to me that I am countering the rotation by the code supplied in the keyboard_check_released spot. If you know any other way I can code it please to tell me.

create event
punchingrotation = 0;


stepevent
mainattack = keyboard_check_pressed(ord("C"))

if mainattack
{
if punchingrotation == 0
{
sprite_index = s_rightpunch
}
if punchingrotation == 1
{
sprite_index = s_leftpunch
}

}
if keyboard_check_released(ord("C"))
{
if punchingrotation == 0
{
punchingrotation = 1
}
if punchingrotation == 1
{
punchingrotation = 0
}

}
 
K

Kris Hyre

Guest
Code:
if keyboard_check_released(ord("C"))
{
    if punchingrotation == 0
    {
        punchingrotation = 1
    }
    if punchingrotation == 1
    {
        punchingrotation = 0
    }
}
Here you are checking if
punchingrotation == 0, if it does, you set it to 1. THEN you check to see if
punchingrotation == 1, which it does, you just set it to that, and you then set it back to 0.

Since it is always 0, you always get right punches.

if+else, not if+if
 
A

Allegro

Guest
You may want to put this into a keypressed event rather than step, because as long as the condition is met to make the sprite's index be a sprite, it will be that sprite.
 
T

Tanner021

Guest
Code:
if keyboard_check_released(ord("C"))
{
    if punchingrotation == 0
    {
        punchingrotation = 1
    }
    if punchingrotation == 1
    {
        punchingrotation = 0
    }
}
Here you are checking if
punchingrotation == 0, if it does, you set it to 1. THEN you check to see if
punchingrotation == 1, which it does, you just set it to that, and you then set it back to 0.

Since it is always 0, you always get right punches.

if+else, not if+if
Thanks mate, that was a very simple solution.
 
Top