Locking directions issue

SGDK only sub forum

Moderator: Stef

Post Reply
orlanrod
Very interested
Posts: 99
Joined: Fri Sep 25, 2015 7:46 pm

Locking directions issue

Post by orlanrod » Sat Oct 10, 2015 6:13 am

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.

djcouchycouch
Very interested
Posts: 710
Joined: Sat Feb 18, 2012 2:44 am

Re: Locking directions issue

Post by djcouchycouch » Sat Oct 10, 2015 11:21 am

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.

orlanrod
Very interested
Posts: 99
Joined: Fri Sep 25, 2015 7:46 pm

Re: Locking directions issue

Post by orlanrod » Sat Oct 10, 2015 6:42 pm

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.

Sik
Very interested
Posts: 939
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: Locking directions issue

Post by Sik » Sun Oct 11, 2015 12:00 am

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").
Sik is pronounced as "seek", not as "sick".

orlanrod
Very interested
Posts: 99
Joined: Fri Sep 25, 2015 7:46 pm

Re: Locking directions issue

Post by orlanrod » Sun Oct 11, 2015 3:29 am

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.

Post Reply