Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make my character dash - Double Key Press
    primarykey
    data
    text
    <p>I'm creating a beat em up game and so far i have the character running and jumping. I now want to make my character to dash left or right. So if the player presses the key right, right very quickly then the character will dash. How can i make this happen. This is what I have done so far.</p> <pre><code>package { import flash.display.MovieClip; import flash.events.Event; import flash.events.KeyboardEvent; import flash.ui.Keyboard; public class Player extends MovieClip { //Player run speed setting var RunSpeed:Number = 8; //Player key presses var RightKeyPress:Boolean = false; var LeftKeyPress:Boolean = false; var UpKeyPress:Boolean = false; //Jump variables var Gravity:Number = 1.5; var JumpPower:Number = 0; var CanJump:Boolean = false; var Jumped:Boolean = false; public function Player() { // constructor code stage.addEventListener(KeyboardEvent.KEY_DOWN,KeyPressed); addEventListener(Event.ENTER_FRAME,Update); stage.addEventListener(KeyboardEvent.KEY_UP,KeyReleased); } function KeyPressed(event:KeyboardEvent) { //When Key is Down if (event.keyCode == 39) { RightKeyPress = true; } if (event.keyCode == 37) { LeftKeyPress = true; } if (event.keyCode == 38) { UpKeyPress = true; } } function Update(event:Event) { //Adding gravity to the game world JumpPower += Gravity; //if player is more than 300 on the y-axis if (this.y &gt; 300) { //Player stays on the ground and can jump JumpPower = 0; CanJump = true; } //If on floor if (CanJump) { //If right key is pressed run right if ((RightKeyPress)) { x += RunSpeed; gotoAndStop('Run'); scaleX = 1; } else if ((LeftKeyPress)) { //otherwise if left key is pressed run left x -= RunSpeed; gotoAndStop('Run'); scaleX = -1; } if ((UpKeyPress)) { //If up key is pressed then jump JumpPower = -15; CanJump = false; gotoAndStop('Jump'); Jumped = true; } //If no key is pressed stay idle if ((!RightKeyPress &amp;&amp; !LeftKeyPress &amp;&amp; CanJump)) { gotoAndStop('Idle'); } } else if (CanJump == false) { //Other if in air and right key is pressed move right if ((RightKeyPress)) { x += RunSpeed; scaleX = 1; } else if ((LeftKeyPress)) { //Otherwise if left key is pressed then move left x -= RunSpeed; scaleX = -1; } } //If already jumped and on floor if (Jumped == true &amp;&amp; CanJump) { //Cannot jump again CanJump = false; //If on floor and right key is pressed run right if ((RightKeyPress)) { gotoAndStop('Run'); scaleX = 1; } else if ((LeftKeyPress)) { //Otherwise if on floor and left key is pressed run left gotoAndStop('Run'); scaleX = -1; } //If no key is pressed stay idle if ((!RightKeyPress &amp;&amp; !LeftKeyPress)) { gotoAndStop('Idle'); } } this.y += JumpPower; } function KeyReleased(event:KeyboardEvent) { if (event.keyCode == 39) { event.keyCode = 0; RightKeyPress = false; } if (event.keyCode == 37) { event.keyCode = 0; LeftKeyPress = false; } if (event.keyCode == 38) { event.keyCode = 0; UpKeyPress = false; Jumped = false; } } } } </code></pre>
    singulars
    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.
 

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