00:00
00:00
Newgrounds Background Image Theme

Someone gifted MetalSlayer69 supporter status!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

AS2 Weird Specific Control Quirk

647 Views | 6 Replies
New Topic Respond to this Topic

AS2 Weird Specific Control Quirk 2023-03-12 15:24:57


So, I coded this test swf. Please give it a short play. Use the arrow keys to navigate and the spacebar to build up a short bash.


One thing you should notice while playing is that you can enter 'state 2' while moving up, down, left, right, up+right, or down+left.


BUT if you move up+left or down+right you can't enter 'state 2' at all unless you're still holding space as you let go of the keys necessary to propel yourself in those directions, which (to me) feels awkward to do in contrast to how the other directions work. I'd like to fix it, but I don't know what's causing the problem.


The code to maneuver the 'ghost' looks like this:

        //use LEFT & RIGHT to move
        if(Key.isDown(Key.LEFT)) {
            ghosty.xSpeed -= ghosty.xAccel;
            ghosty.xDecel = 0;
            ghosty.drctMe._rotation = 180;
        }
        if(Key.isDown(Key.RIGHT)) {
            ghosty.xSpeed += ghosty.xAccel;
            ghosty.xDecel = 0;
            ghosty.drctMe._rotation = 0;
        }
        //use LEFT & RIGHT to move
        
        //use UP & DOWN to move
        if(Key.isDown(Key.UP)) {
            ghosty.ySpeed -= ghosty.yAccel;
            ghosty.yDecel = 0;
            ghosty.drctMe._rotation = 270;
        }
        if(Key.isDown(Key.DOWN)) {
            ghosty.ySpeed += ghosty.yAccel;
            ghosty.yDecel = 0;
            ghosty.drctMe._rotation = 90;
        }
        //use UP & DOWN to move
        
        //more rotation stuff
        if(Key.isDown(Key.LEFT) && Key.isDown(Key.DOWN)) {
            ghosty.drctMe._rotation = 135;
        }
        if(Key.isDown(Key.LEFT) && Key.isDown(Key.UP)) {
            ghosty.drctMe._rotation = 225;
        }
        if(Key.isDown(Key.RIGHT) && Key.isDown(Key.UP)) {
            ghosty.drctMe._rotation = 315;
        }
        if(Key.isDown(Key.RIGHT) && Key.isDown(Key.DOWN)) {
            ghosty.drctMe._rotation = 45;
        }
        //more rotation stuff


The code that switches between states looks like this:

    //changes the state of ghost
    if(Key.isDown(Key.SPACE)) {
        twobular = true;
    }else {
        twobular = false;
    }
    if(twobular == true) {
        ghosty.st = 2;
        ghosty.invul += 4;
        if(ghosty.invul >= 12) {
            ghosty.invul = 12;
        }
    }
    if(twobular == false && ghosty.invul > 0 && ghosty.st == 2) {
        ghosty.st = 0;
    }
    if(twobular == false && ghosty.invul <= 6 && ghosty.st == 0) {
        ghosty.st = 1;
    }


Could someone please offer an explanation as to why this is happening to the directions for up+left and down+right specifically? Is it just too many if statements? I'm so confused.


[1] - [2]

Response to AS2 Weird Specific Control Quirk 2023-03-13 05:38:50


I'm not sure I'm following what the problem is, I can press space and bounce in any direction - any combination of keys works the same. I move in a direction, press space which stops my movement. And then when I release space I fly in the direction I was travelling. There's nothing different about any one direction.


Your code in general could use a clean up though. You probably want some else statements in there (press and hold left and then press right and you'll move left whilst facing right).


And there's no need to say if(twobular == true), you can just use if(twobular) and if(!twobular) instead of twobular == false


Your code doesn't cause this issue. It's actually because of a fundamental limitation with the keyboard: keyboards are generally split up into 'zones', and sometimes you cannot press more than a set of keys in a zone (if I understand it correctly).


Try an online keyboard test, e.g. this website; press up+left+space, and you'll see that you can't press/hold more than two of the three keys simultaneously.


The fix is simple; use a different key instead of the spacebar. Although numpad up+left+space works, not everyone has a numpad so I wouldn't use that - instead of spacebar, try something like X or C. For this, replace the Key.SPACE with the key code for X or C, which based on this website, is the number 88 and 67 respectively. You can use Z too, but its position in french/AZERTY keyboards means it'll be in a completely different row; for consistency, X, C or V is probably better.


Slint approves of me! | "This is Newgrounds.com, not Disney.com" - WadeFulp

"Sit look rub panda" - Alan Davies

BBS Signature

Response to AS2 Weird Specific Control Quirk 2023-03-13 14:33:51


At 3/13/23 05:38 AM, blit-blat wrote: I'm not sure I'm following what the problem is, I can press space and bounce in any direction - any combination of keys works the same. I move in a direction, press space which stops my movement. And then when I release space I fly in the direction I was travelling. There's nothing different about any one direction.


You were making me feel crazy until I tested the game on a different computer in my house. I discovered that there might be something wrong with my laptop's keyboard. Lucky me.


Your code in general could use a clean up though. You probably want some else statements in there (press and hold left and then press right and you'll move left whilst facing right).

And there's no need to say if(twobular == true), you can just use if(twobular) and if(!twobular) instead of twobular == false


Is this better?

    //changes the state of ghost
    if(Key.isDown(Key.SPACE) && bashDelay == 12) {
        twobular = true;
    }else {
        twobular = false;
    }
    if(twobular) {
        ghosty.st = 2;
        ghosty.invul += 3;
        if(ghosty.invul >= 6) {
            ghosty.invul = 6;
        }
    }
    if(!twobular && ghosty.invul > 0 && ghosty.st == 2) {
        ghosty.st = 0;
        bashDelay = 0;
    }
    if(!twobular && ghosty.invul <= 2 && ghosty.st == 0) {
        ghosty.st = 1;
    }


Pardon my lack of experience, I don't understand how to implement the else statements in the best fashion. Something like this?

        //use LEFT & RIGHT to move
        if(Key.isDown(Key.LEFT)) {
            ghosty.xSpeed -= ghosty.xAccel;
            ghosty.xDecel = 0;
            ghosty.drctMe._rotation = 180;
        } else if(Key.isDown(Key.RIGHT)) {
            ghosty.xSpeed += ghosty.xAccel;
            ghosty.xDecel = 0;
            ghosty.drctMe._rotation = 0;
        }
        //use LEFT & RIGHT to move
        
        //use UP & DOWN to move
        if(Key.isDown(Key.UP)) {
            ghosty.ySpeed -= ghosty.yAccel;
            ghosty.yDecel = 0;
            ghosty.drctMe._rotation = 270;
        } else if(Key.isDown(Key.DOWN)) {
            ghosty.ySpeed += ghosty.yAccel;
            ghosty.yDecel = 0;
            ghosty.drctMe._rotation = 90;
        }
        //use UP & DOWN to move


It fixed the issue you were referring to, where you could aim right while still moving left. Thanks for pointing that out.


[1] - [2]

Response to AS2 Weird Specific Control Quirk 2023-03-13 14:41:04


At 3/13/23 02:33 PM, Nabella wrote: You were making me feel crazy until I tested the game on a different computer in my house. I discovered that there might be something wrong with my laptop's keyboard. Lucky me.

To be fair, a lot of people play on laptops and not all desktop/mechanical keyboards are guaranteed to work correctly either. I faced the same issue as you, so it's likely that others will too.

And there's no need to say if(twobular == true), you can just use if(twobular) and if(!twobular) instead of twobular == false
Is this better?
Pardon my lack of experience, I don't understand how to implement the else statements in the best fashion. Something like this?

Yep, that's correct.


Slint approves of me! | "This is Newgrounds.com, not Disney.com" - WadeFulp

"Sit look rub panda" - Alan Davies

BBS Signature

Response to AS2 Weird Specific Control Quirk 2023-03-13 15:18:28


At 3/13/23 02:32 PM, Gimmick wrote: Your code doesn't cause this issue. It's actually because of a fundamental limitation with the keyboard: keyboards are generally split up into 'zones', and sometimes you cannot press more than a set of keys in a zone (if I understand it correctly).

Try an online keyboard test, e.g. this website; press up+left+space, and you'll see that you can't press/hold more than two of the three keys simultaneously.

The fix is simple; use a different key instead of the spacebar. Although numpad up+left+space works, not everyone has a numpad so I wouldn't use that - instead of spacebar, try something like X or C.


Would you look at that, I'm learning something new everyday.


At 3/13/23 02:41 PM, Gimmick wrote:
At 3/13/23 02:33 PM, Nabella wrote: You were making me feel crazy until I tested the game on a different computer in my house. I discovered that there might be something wrong with my laptop's keyboard. Lucky me.
To be fair, a lot of people play on laptops and not all desktop/mechanical keyboards are guaranteed to work correctly either. I faced the same issue as you, so it's likely that others will too.
And there's no need to say if(twobular == true), you can just use if(twobular) and if(!twobular) instead of twobular == false
Is this better?
Pardon my lack of experience, I don't understand how to implement the else statements in the best fashion. Something like this?
Yep, that's correct.


Now it controls a bit like Spelunky, hehe.


Y'know, this is kind of abrupt, as is the case with our usual encounters, but I've been meaning to share with you the scrappy little tech demos I've been making these past two months. I wanted to get a second opinion about which I should continue with. I've been thinking about just following through with the third one given that it's the simplest one to draw graphics for.

cameraTest3

circleClicker0.5

GirlwithPlates


[1] - [2]

Response to AS2 Weird Specific Control Quirk 2023-03-20 12:50:07


At 3/13/23 03:18 PM, Nabella wrote: Y'know, this is kind of abrupt, as is the case with our usual encounters, but I've been meaning to share with you the scrappy little tech demos I've been making these past two months. I wanted to get a second opinion about which I should continue with. I've been thinking about just following through with the third one given that it's the simplest one to draw graphics for.
cameraTest3
circleClicker0.5
GirlwithPlates


I think all of them are fine to continue with! You could do them in order of whichever one you're more comfortable with. Even if it's conceptually "simple", it can still be a good time-pleaser, gameplay-wise. Plus, if it helps you become better at programming/gamedev, all the better!


Slint approves of me! | "This is Newgrounds.com, not Disney.com" - WadeFulp

"Sit look rub panda" - Alan Davies

BBS Signature