Note that there are some explanatory texts on larger screens.

plurals
  1. POSequentially-specific combination of keys held for function?
    primarykey
    data
    text
    <p>I'm trying to give my character in a platformer game a movement mechanic in which holding the left key then also the right will cause the character to still move left but at a slower pace (i.e. movementSpeed/2) as if moon-walking (and visa versa):</p> <pre><code> public var leftKey:Boolean = false; public var rightKey:Boolean = false; public var upKey:Boolean = false; public var leftFlag:Boolean = false; function ifKeyDown(event:KeyboardEvent):void { if (event.keyCode == Keyboard.LEFT &amp;&amp; rightKey == false) { leftKey = true; if (event.keyCode == Keyboard.LEFT &amp;&amp; event.keyCode == Keyboard.RIGHT) { leftFlag = true; trace("leftFlag true"); } } if (event.keyCode == Keyboard.RIGHT &amp;&amp; leftKey == false) { rightKey = true; } } function ifKeyUp(event:KeyboardEvent):void { if (event.keyCode == Keyboard.LEFT) { leftKey = false; leftFlag = false; } if (event.keyCode == Keyboard.RIGHT) { rightKey = false; } } public function ifEnterFrame(event:Event):void { if (leftKey == true &amp;&amp; leftFlag == false) { player1_mc.x -= mainSpeed; trace("L"); } if (rightKey == true &amp;&amp; leftFlag == false) { player1_mc.x += mainSpeed; trace("R"); } if (leftKey == true &amp;&amp; rightKey == true) { if (leftFlag == true) { player1_mc.x -= mainSpeed/2; trace("L + R"); } else { player1_mc.x += mainSpeed/2; trace("R + L"); } } </code></pre> <p>My output would look like this: <em>I hold left key</em> L L L L <em>I let go of left key. Then, I hold right key</em> R R R R <em>I let go of right key. Then, I hold right then also hold left</em> L R R+L L R R+L <em>I let go of both. Then, I hold left then also right</em> L R R+L L R R+L</p> <p>Though I know by my traces that the leftFlag is not being run, I've spent hours trying to figure out why to no avail. :(</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload