Note that there are some explanatory texts on larger screens.

plurals
  1. POCharacter Jump with Animation
    primarykey
    data
    text
    <p>Im trying to create a platform game but im struggling with the jump part of the game. I have got the jump working but when I try to add the animation it goes all wrong. When I hit the jump button it jumps but when i lands it gets stuck on the end of the jump animation until i move. Secondly when i jump and press the right or left button it jumps but plays the run animation while i try to move in mid air. How can i resolve these problems</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 Yvelocity:Number = 0; var CanJump: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 Yvelocity += Gravity; //if player is more than 300 on the y-axis if (this.y &gt; 300) { //Player stays on the ground and can jump Yvelocity = 0; CanJump = true; } if ((RightKeyPress == true)) { x += RunSpeed; gotoAndStop('Run'); scaleX = 1; } else if ((LeftKeyPress == true)) { x -= RunSpeed; gotoAndStop('Run'); scaleX = -1; } if ((UpKeyPress == true &amp;&amp; CanJump)) { Yvelocity = -15; CanJump = false; gotoAndStop('Jump'); } this.y += Yvelocity; } function KeyReleased(event:KeyboardEvent) { if (event.keyCode == 39) { event.keyCode = 0; RightKeyPress = false; gotoAndStop('Idle'); } if (event.keyCode == 37) { event.keyCode = 0; LeftKeyPress = false; gotoAndStop('Idle'); } if (event.keyCode == 38) { event.keyCode = 0; UpKeyPress = false; } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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