Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Problem with more keys pressed at once

New Here ,
Sep 19, 2013 Sep 19, 2013

Hello i am making a two player platform game, with two characters. I have a kinda strange problem, if both characters walk left and jump at the same time everything is good, but if both characters walk right and jump at the same time only one of them will do so. Does anyone of you have an explanation for this or a solution?

Any help is appreciated

TOPICS
ActionScript
532
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Sep 19, 2013 Sep 19, 2013

without showing any of your code, you are likely to get no usable advice 😉

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 19, 2013 Sep 19, 2013

This is not my code but it shows my exact problem

var upPressed:Boolean = false;

var downPressed:Boolean = false;

var leftPressed:Boolean = false;

var rightPressed:Boolean = false;

var WPressed:Boolean = false;

var SPressed:Boolean = false;

var APressed:Boolean = false;

var DPressed:Boolean = false;

box2.addEventListener(Event.ENTER_FRAME, fl_MoveInDirectionOfKey);

stage.addEventListener(KeyboardEvent.KEY_DOWN, fl_SetKeyPressed);

stage.addEventListener(KeyboardEvent.KEY_UP, fl_UnsetKeyPressed);

function fl_MoveInDirectionOfKey(event:Event)

{

    if (upPressed)

    {

        box2.y -= 5;

    }

    if (downPressed)

    {

        box2.y += 5;

    }

    if (leftPressed)

    {

        box2.x -= 5;

    }

    if (rightPressed)

    {

        box2.x += 5;

    }

    if (WPressed)

    {

        box1.y -= 5;

    }

    if (SPressed)

    {

        box1.y += 5;

    }

    if (APressed)

    {

        box1.x -= 5;

    }

    if (DPressed)

    {

        box1.x += 5;

    }

}

function fl_SetKeyPressed(event:KeyboardEvent):void

{

    switch (event.keyCode)

    {

        case Keyboard.UP:

        {

            upPressed = true;

            break;

        }

        case Keyboard.DOWN:

        {

            downPressed = true;

            break;

        }

        case Keyboard.LEFT:

        {

            leftPressed = true;

            break;

        }

        case Keyboard.RIGHT:

        {

            rightPressed = true;

            break;

        }

        case Keyboard.W:

        {

            WPressed = true;

            break;

        }

        case Keyboard.S:

        {

            SPressed = true;

            break;

        }

        case Keyboard.A:

        {

            APressed = true;

            break;

        }

        case Keyboard.D:

        {

            DPressed = true;

            break;

        }

    }

}

function fl_UnsetKeyPressed(event:KeyboardEvent):void

{

    switch (event.keyCode)

    {

        case Keyboard.UP:

        {

            upPressed = false;

            break;

        }

        case Keyboard.DOWN:

        {

            downPressed = false;

            break;

        }

        case Keyboard.LEFT:

        {

            leftPressed = false;

            break;

        }

        case Keyboard.RIGHT:

        {

            rightPressed = false;

            break;

        }

        case Keyboard.W:

        {

            WPressed = false;

            break;

        }

        case Keyboard.S:

        {

            SPressed = false;

            break;

        }

        case Keyboard.A:

        {

            APressed = false;

            break;

        }

        case Keyboard.D:

        {

            DPressed = false;

            break;

        }

    }

}

Why can't i make both boxes move towards the right corner at the same time?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 19, 2013 Sep 19, 2013
LATEST

Never mind, turns out i did everything right. Problem is i have an usually stupid computer - i tested my game on another laptop and it works perfectly... So wierd

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines