Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
without showing any of your code, you are likely to get no usable advice 😉
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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
Find more inspiration, events, and resources on the new Adobe Community
Explore Now