Page 1 of 1

Locking directions issue

Posted: Sat Oct 10, 2015 6:13 am
by orlanrod
I'm having an issue locking movement to 4 directions.

If you hold left arrow then hold right arrow, it will ignore the right arrow. But if you do it the opposite direction it triggers left even if the variable is set to the other direction. Likewise, if you hold up arrow, then you hold down arrow it ignores down. But doing the opposite does the same problem as left/right. I think its a bug or something with gens emulator? Here is the code.

if ((player1.current_anim == ANIM_STANDSIDES) | (player1.current_anim == ANIM_STANDDOWN) | (player1.current_anim == ANIM_STANDUP)) {player1.lockdir = 1; }

if ((value & BUTTON_UP) && player1.lockdir == 1) player1.lockdir = 2;
if ((value & BUTTON_DOWN) && player1.lockdir == 1) player1.lockdir = 3;
if ((value & BUTTON_LEFT) && player1.lockdir == 1) player1.lockdir = 4;
if ((value & BUTTON_RIGHT) && player1.lockdir == 1) player1.lockdir = 5;


if ((value & BUTTON_UP) && player1.y > 5 && tileproperty == TILEPROP_NOTSOLID && player1.lockdir == 2) { player1.y -= 1; SPR_setPosition(&sprites[player1.zorder], player1.x, player1.y); }

if ((value & BUTTON_DOWN) && player1.y < 176 && tileproperty == TILEPROP_NOTSOLID && player1.lockdir == 3) { player1.y += 1; SPR_setPosition(&sprites[player1.zorder], player1.x, player1.y); }

if ((value & BUTTON_LEFT) && passScreen == 1 && tileproperty == TILEPROP_NOTSOLID && player1.lockdir == 4) { player1.x -= 1; SPR_setPosition(&sprites[player1.zorder], player1.x, player1.y); }

if ((value & BUTTON_RIGHT) && passScreen == 1 && tileproperty == TILEPROP_NOTSOLID && player1.lockdir == 5) { player1.

Re: Locking directions issue

Posted: Sat Oct 10, 2015 11:21 am
by djcouchycouch
Considering that physically on a dpad you can't press both left and right, I'm not sure what the system will give you.

You could also check for button presses instead of button state. A press being a button up state on the previous frame and a button down state on the current frame.

Re: Locking directions issue

Posted: Sat Oct 10, 2015 6:42 pm
by orlanrod
djcouchycouch wrote:Considering that physically on a dpad you can't press both left and right, I'm not sure what the system will give you.

You could also check for button presses instead of button state. A press being a button up state on the previous frame and a button down state on the current frame.
Yeah, i am just making sure if they play on an emulator they can't do that.

Re: Locking directions issue

Posted: Sun Oct 11, 2015 12:00 am
by Sik
Yeah, emulators explicitly override directions like that, apparently a few games freak out if you press opposite directions. Fusion lets you disable this if you need to test this behavior.

Real hardware in theory will just give you nothing because the D-pad ends up centered and hence pressing nothing. In practice you can end up getting it to press opposing directions if you push too hard, so better to account for it if you can (even if it's "ignore both presses").

Re: Locking directions issue

Posted: Sun Oct 11, 2015 3:29 am
by orlanrod
Sik wrote:Yeah, emulators explicitly override directions like that, apparently a few games freak out if you press opposite directions. Fusion lets you disable this if you need to test this behavior.

Real hardware in theory will just give you nothing because the D-pad ends up centered and hence pressing nothing. In practice you can end up getting it to press opposing directions if you push too hard, so better to account for it if you can (even if it's "ignore both presses").
Oh i see. I'll take account for that.

Thanks.