AS3 jumping problem

Need programming help? Want to post programming tips? Are you programming a game and want to show it off? That and more here.

AS3 jumping problem

Postby Konradix » June 27th, 2011, 12:05 pm

The code:
Code: Select all
var rightKeyisDown:Boolean=false;
var leftKeyisDown:Boolean=false;
var upKeyisDown:Boolean=false;
var downKeyisDown:Boolean=false;

var gravity:Number=1;
var yVelocity:Number=0;
var canJump:Boolean=false;

stage.addEventListener(KeyboardEvent.KEY_DOWN,PressAKey);
stage.addEventListener(KeyboardEvent.KEY_UP,ReleaseAKey);

function PressAKey(event:KeyboardEvent):void {
   if (event.keyCode==Keyboard.RIGHT) {
      rightKeyisDown=true;
   }
   if (event.keyCode==Keyboard.LEFT) {
      leftKeyisDown=true;
   }
   if (event.keyCode==Keyboard.UP) {
      upKeyisDown=true;
   }
   if (event.keyCode==Keyboard.DOWN) {
      downKeyisDown=true;
   }
}

function ReleaseAKey(event:KeyboardEvent):void {
   if (event.keyCode==Keyboard.RIGHT) {
      rightKeyisDown=false;
   }
   if (event.keyCode==Keyboard.LEFT) {
      leftKeyisDown=false;
   }
   if (event.keyCode==Keyboard.UP) {
      upKeyisDown=false;
   }
   if (event.keyCode==Keyboard.DOWN) {
      downKeyisDown=false;
   }
}

circle.addEventListener(Event.ENTER_FRAME,moveTheCircle);

function moveTheCircle(event:Event):void {

   if (rightKeyisDown) {

      circle.x+=5;
   }
   if (leftKeyisDown) {

      circle.x-=5;
   }
   if (upKeyisDown&&canJump) {

      yVelocity=-15;
      canJump=false;
   }
   yVelocity+=gravity;

   if (! floor.hitTestPoint(circle.x,circle.y,true)) {

      circle.y+=yVelocity;

   }
   if (yVelocity>20) {

      yVelocity=20;
   }

   for (var i,int = 0; i<10; i++) {
      if (floor.hitTestPoint(circle.x,circle.y,true)) {

         circle.y--;
         yVelocity=0;
         canJump=true;
      }
   }
}


I'm following this tutorial:
http://www.youtube.com/watch?v=Z160NtbM ... ion_112532 - part 1
http://www.youtube.com/watch?v=LVaEZMii ... re=related - part 2

I am doing everything right, I have no errors, but my character refuses to jump. I mash up key like crazy, watch tutorial back, mash up key, check my code, mash up key, test etc.

I would ask the creator of the video to help me, but the problem is that those tutorials were relased nearly year ago, so I doubt he'll remember.

Thanks in advance
"Men cry not for themselves, but for their comrades"

Check out my newest level called:
Image
Be sure to leave a comment and a rating ;)
Fun and Games: show
Levels that I may make by 20XX
- Remake of Airship Armada
- Level using the Turbo FLUDD
- Level using the Flying Cap
- A level on the moon

- Syzygy Labs
- Maybe some sort of Metroidvania level
- Sneaking level
- A mystery


Random Stuff
Image
Image
Czasoprzestrzen/Spacetime... If only somebody knew this hidden gem...

Huh?
GENERATION 31: The first time you see this, copy it into your sig on any forum and add 1 to the generation. Social experiment.
User avatar
Konradix
The Legacy

 
Posts: 689
Joined: May 12th, 2010, 8:14 am
Location: Studying the Grand History in the Ruins of the World

Runolympics 2015 Participation

Thumbs Up given: 85 times
Thumbs Up received: 39 times

Re: AS3 jumping problem

Postby Buff_ » June 29th, 2011, 4:17 am

Konradix wrote:I would ask the creator of the video to help me, but the problem is that those tutorials were relased nearly year ago, so I doubt he'll remember.


He replied to someone's comment 3 weeks ago. That's pretty recent, so I suggest asking him.
User avatar
Buff_
A rather stellar gentleman

Error contacting Twitter
 
Posts: 2827
Joined: August 7th, 2009, 6:48 am
Location: Under the sink

The Start of Something Big

Thumbs Up given: 10 times
Thumbs Up received: 104 times


Return to Programming