Directional key controller animations not working.

M

Magic-4e

Guest
Hi everyone I am working on a little project here and I have made a fully functional movement controls for the directional keys the only problem is that my animation sprites won't play when I push the buttons.
2 of them work fine(left and right) but the other 2(up and down) are always stuck on the first frame.
I looked over it a couple of times and the 2 sets of code have the exact same code and should work in the same way.
I have tried to run the up and down animation code separately and then they seemed to work and when I place them back where they belong they freeze again.
I just don't understand.
Can somebody help me?

Here is my code for the directional movement:

Code:
if (global.Game_End == 0)
{
    if (keyboard_check(vk_left) + keyboard_check(vk_up) + keyboard_check(vk_right) + keyboard_check(vk_down))
    {
        if (keyboard_check(vk_left) + keyboard_check(vk_right))
        {
            if (keyboard_check(vk_left))
            {
                hspeed = -8;
                if (sprite_index != IK_links_loop_spr)
                {
                    image_index = 0;
                    sprite_index = IK_links_loop_spr;
                    image_speed = 0.5;
                    Direction = 3;
                }
            }
            if (keyboard_check(vk_right))
            {
                hspeed = 8;
                if (sprite_index != IK_rechts_loop_spr)
                {
                    image_index = 0;
                    sprite_index = IK_rechts_loop_spr;
                    image_speed = 0.5;
                    Direction = 1;
                }
            }
        }
        else
        {
            hspeed = 0;
            if (hspeed == 0)
            {
                if (Direction == 1)
                {
                    sprite_index = IK_rechts_spr;
                }
                else
                {
                    if (Direction == 2)
                    {
                        sprite_index = IK_voorkant_spr;
                    }
                    else
                    {
                        if (Direction == 3)
                        {
                            sprite_index = IK_links_spr;
                        }
                        else
                        {
                            if (Direction == 4)
                            {
                                sprite_index = IK_achterkant_spr;
                            }
                        }
                    }
                }
            }
        }
        if (keyboard_check(vk_up) + keyboard_check(vk_down))
        {
            if (keyboard_check(vk_up))
            {
                vspeed = -8;
                if (sprite_index != IK_achterkant_loop_spr)
                {
                    image_index = 0;
                    sprite_index = IK_achterkant_loop_spr;
                    image_speed = 0.5;
                    Direction = 4;
                }
            }
            if (keyboard_check(vk_down))
            {
                vspeed = 8;
                if (sprite_index != IK_voorkant_loop_spr)
                {
                    image_index = 0;
                    sprite_index = IK_voorkant_loop_spr;
                    image_speed = 0.5;
                    Direction = 2;
                }
            }
        }
        else
        {
            vspeed = 0;
            if (hspeed == 0)
            {
                if (Direction == 1)
                {
                    sprite_index = IK_rechts_spr;
                }
                else
                {
                    if (Direction == 2)
                    {
                        sprite_index = IK_voorkant_spr;
                    }
                    else
                    {
                        if (Direction == 3)
                        {
                            sprite_index = IK_links_spr;
                        }
                        else
                        {
                            if (Direction == 4)
                            {
                                sprite_index = IK_achterkant_spr;
                            }
                        }
                    }
                }
            }
        }
    }
    else
    {
        hspeed = 0;
        vspeed = 0;
        if (Direction == 1)
        {
            sprite_index = IK_rechts_spr;
        }
        else
        {
            if (Direction == 2)
            {
                sprite_index = IK_voorkant_spr;
            }
            else
            {
                if (Direction == 3)
                {
                    sprite_index = IK_links_spr;
                }
                else
                {
                    if (Direction == 4)
                    {
                        sprite_index = IK_achterkant_spr;
                    }
                }
            }
        }
    }
}
else
{
    hspeed = 0;
    vspeed = 0;
    if (Direction == 1)
    {
        sprite_index = IK_rechts_spr;
    }
    else
    {
        if (Direction == 2)
        {
            sprite_index = IK_voorkant_spr;
        }
        else
        {
            if (Direction == 3)
            {
                sprite_index = IK_links_spr;
            }
            else
            {
                if (Direction == 4)
                {
                    sprite_index = IK_achterkant_spr;
                }
            }
        }
    }
}
If you need any more information just let me know. :)
 
M

maratae

Guest
Hi everyone I am working on a little project here and I have made a fully functional movement controls for the directional keys the only problem is that my animation sprites won't play when I push the buttons.
2 of them work fine(left and right) but the other 2(up and down) are always stuck on the first frame.
I looked over it a couple of times and the 2 sets of code have the exact same code and should work in the same way.
I have tried to run the up and down animation code separately and then they seemed to work and when I place them back where they belong they freeze again.
I just don't understand.
Can somebody help me?

Here is my code for the directional movement:

Code:
if (global.Game_End == 0)
{
    if (keyboard_check(vk_left) + keyboard_check(vk_up) + keyboard_check(vk_right) + keyboard_check(vk_down))
    {
        if (keyboard_check(vk_left) + keyboard_check(vk_right))
        {
            if (keyboard_check(vk_left))
            {
                hspeed = -8;
                if (sprite_index != IK_links_loop_spr)
                {
                    image_index = 0;
                    sprite_index = IK_links_loop_spr;
                    image_speed = 0.5;
                    Direction = 3;
                }
            }
            if (keyboard_check(vk_right))
            {
                hspeed = 8;
                if (sprite_index != IK_rechts_loop_spr)
                {
                    image_index = 0;
                    sprite_index = IK_rechts_loop_spr;
                    image_speed = 0.5;
                    Direction = 1;
                }
            }
        }
        else
        {
            hspeed = 0;
            if (hspeed == 0)
            {
                if (Direction == 1)
                {
                    sprite_index = IK_rechts_spr;
                }
                else
                {
                    if (Direction == 2)
                    {
                        sprite_index = IK_voorkant_spr;
                    }
                    else
                    {
                        if (Direction == 3)
                        {
                            sprite_index = IK_links_spr;
                        }
                        else
                        {
                            if (Direction == 4)
                            {
                                sprite_index = IK_achterkant_spr;
                            }
                        }
                    }
                }
            }
        }
        if (keyboard_check(vk_up) + keyboard_check(vk_down))
        {
            if (keyboard_check(vk_up))
            {
                vspeed = -8;
                if (sprite_index != IK_achterkant_loop_spr)
                {
                    image_index = 0;
                    sprite_index = IK_achterkant_loop_spr;
                    image_speed = 0.5;
                    Direction = 4;
                }
            }
            if (keyboard_check(vk_down))
            {
                vspeed = 8;
                if (sprite_index != IK_voorkant_loop_spr)
                {
                    image_index = 0;
                    sprite_index = IK_voorkant_loop_spr;
                    image_speed = 0.5;
                    Direction = 2;
                }
            }
        }
        else
        {
            vspeed = 0;
            if (hspeed == 0)
            {
                if (Direction == 1)
                {
                    sprite_index = IK_rechts_spr;
                }
                else
                {
                    if (Direction == 2)
                    {
                        sprite_index = IK_voorkant_spr;
                    }
                    else
                    {
                        if (Direction == 3)
                        {
                            sprite_index = IK_links_spr;
                        }
                        else
                        {
                            if (Direction == 4)
                            {
                                sprite_index = IK_achterkant_spr;
                            }
                        }
                    }
                }
            }
        }
    }
    else
    {
        hspeed = 0;
        vspeed = 0;
        if (Direction == 1)
        {
            sprite_index = IK_rechts_spr;
        }
        else
        {
            if (Direction == 2)
            {
                sprite_index = IK_voorkant_spr;
            }
            else
            {
                if (Direction == 3)
                {
                    sprite_index = IK_links_spr;
                }
                else
                {
                    if (Direction == 4)
                    {
                        sprite_index = IK_achterkant_spr;
                    }
                }
            }
        }
    }
}
else
{
    hspeed = 0;
    vspeed = 0;
    if (Direction == 1)
    {
        sprite_index = IK_rechts_spr;
    }
    else
    {
        if (Direction == 2)
        {
            sprite_index = IK_voorkant_spr;
        }
        else
        {
            if (Direction == 3)
            {
                sprite_index = IK_links_spr;
            }
            else
            {
                if (Direction == 4)
                {
                    sprite_index = IK_achterkant_spr;
                }
            }
        }
    }
}
If you need any more information just let me know. :)
Let me just say there's a lot of redundancy in your code, and you could probably make it shorter and more readable. But either way,
You have if (hspeed == 0) where you should probably have if (vspeed == 0).
(Did you copy/paste the second part?)

Edit: I'm not sure if that's it, or if what I said works, because I'm having a rather hard time reading the code. Sorry.
 
M

Magic-4e

Guest
Let me just say there's a lot of redundancy in your code, and you could probably make it shorter and more readable. But either way,
You have if (hspeed == 0) where you should probably have if (vspeed == 0).
(Did you copy/paste the second part?)

Edit: I'm not sure if that's it, or if what I said works, because I'm having a rather hard time reading the code. Sorry.
I think the length of my code is fine(I am too lazy to optimize it sorry)
And about that hspeed and vspeed: they are probably fine also cause I don't have any trubbel with my character's movement direction.
If you think it might cause some problems with my animation then please explain why.
Thanks for responding tho. :)
 
Top