Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8587409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:33:46+00:00 2026-06-11T22:33:46+00:00

So, the player can jump using the Spacebar key and has a gravity pulling

  • 0

So, the player can jump using the Spacebar key and has a gravity pulling him towards the floor. What I want is that, if he is not on the floor anymore, you cannot press jump again, till you’ve fall. I tried making a boolean and implementing it the movement, but still no results. Any idea how I could do it?

var keyPressed:int = -1;

player.addEventListener(Event.ENTER_FRAME, iMoveInDirectionOfKey);
stage.addEventListener(KeyboardEvent.KEY_DOWN, iSetKeyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, iUnsetKeyPressed);

function iSetKeyPressed(event:KeyboardEvent):void
{
if (canJump == true) {
    keyPressed = event.keyCode;
} else if (canJump == false) {
    keyPressed = -1;
}
}
function iUnsetKeyPressed(event:KeyboardEvent):void
{
keyPressed = -1;
}
function iMoveInDirectionOfKey(event:Event)
 {
player.y += keyPressed == Keyboard.SPACE ? -20 : 0;
 }

var gravity:Number = 15;
var floor:Number = stage.stageHeight - player.height / 2 + 35;
var canJump:Boolean = true;

iCanJump(canJump);

player.y = floor;

player.addEventListener(Event.ENTER_FRAME, iGravity);

function iGravity(pEvent)
{
if (keyPressed != Keyboard.SPACE) {
    player.y +=  gravity;
}
if (player.y > floor) {
    player.y = floor;
}
}

function iCanJump (canJump:Boolean) {
if (player.y == floor) {
    canJump = true;
} 
if (player.y < floor) {
    canJump = false;
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:33:48+00:00Added an answer on June 11, 2026 at 10:33 pm

    Use a speed variable like this:

    public var jumpSpeed : Number = -20;
    public var ySpeed : Number = 0;
    public var gravity : Number = 1;
    function iSetKeyPressed(e:KeyboardEvent):void
    {
        if(e.keyCode == Keyboard.SPACE && player.y == floor)
            ySpeed = jumpSpeed; 
    }
    
    player.addEventListener(Event.ENTER_FRAME, iGravity);
    
    function iGravity(e : Event)
    {
        player.y += ySpeed;
        if(player.y < floor)
        {
            ySpeed += gravity;
        }
        else
        {
            ySpeed = 0;
            player.y = floor;
        }
    }
    

    You basically create a speed variable for the player and update it each turn.
    You update the player position on y-axis by the player speed as well.

    You can even check the time between frames and multiply the speed by the time to get a smooth result if you continue working on this.

    Good luck.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Examotion has a player that can display the image for svg files as a
I want to create a game where the player only can run and jump
I'm looking for something like the Windows Media Player control that can be hosted
So, I want to create car racing for my RPG game's players. Player can
I am using Quick time via javascript so that I can play video on
anyone that can help would be greatly appreciated. I want to setup a video
I have read a few articles that BlueStacks App Player can be used to
How can I build a simple 2-player game, that communicates over the internet? I
Could somebody tell me how I can make a text that the player can
Are there any limitations on the amount of memory that the Flash player can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.