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

  • SEARCH
  • Home
  • 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 9084959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:07:46+00:00 2026-06-16T21:07:46+00:00

I’m currently building an engine for a platformer game at the moment, but I’ve

  • 0

I’m currently building an engine for a platformer game at the moment, but I’ve noticed that ActionScript3 is having difficulty in keeping fluid when multiple keypresses are in use. For example;

        function onKeyDown(event:KeyboardEvent):void {
        if (event.keyCode == Keyboard.UP || event.keyCode == Keyboard.W || event.keyCode == Keyboard.SPACE) {
            if (isTouchingGround()) {
                isJumping = true;
                yv = -100;
            }
        } else if (event.keyCode == Keyboard.DOWN || event.keyCode == Keyboard.D) {
            if (xv == 0) {
                player.gotoAndPlay(275);
            }
        } else if (event.keyCode == Keyboard.LEFT || event.keyCode == Keyboard.A) {
            if (xv == 0) {
                xv = -24;
            } else if (xv != -120) {
                xv-=2;
            }
        } else if (event.keyCode == Keyboard.RIGHT || event.keyCode == Keyboard.D) {
            if (xv == 0) {
                xv = 24;
            } else if (xv != 120) {
                xv+=2;
            }
        }
    }

So, as listed above, using the UP (or W, or Space) key triggers the player to jump (seperate onframe event handler handles gravity etc). Using the RIGHT (or D..) key triggers increases the player acceleration, which is again applied to the player in a seperate onframe event handler.

Everything works fine by itself – but the problem arises when multiple keystrokes are used. If a player starts to move to the right, and hits jump, he will cease accelerating. At the same time, he will not decelerate, as instructed in the Keyboard.UP method. Instead, he will maintain constant at his current rate, until the RIGHT key is hit again.

In short, it is as though Actionscript begins ignoring both the keyboard.down and keyboard.up methods for the RIGHT or LEFT movement keys, until they are no longer being pressed. This obviously causes for some very rigid gameplay – is there any solution anyone would be willing to share with me on this?

  • 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-16T21:07:47+00:00Added an answer on June 16, 2026 at 9:07 pm

    Your problem lies in the fact that your if conditionals are followed by if else conditionals. Drop the else and just have the if conditionals. Basically if the user holds down space then none of the other if conditionals are going to be tested since space is being held down and it’s the first if statement. So just drop the else off of the if’s. Just remove the if else conditionals that are testing keystrokes, not the conditionals inside of the if statements that deal with keystrokes.

    Here is what your code should look like:

    function onKeyDown(event:KeyboardEvent):void {
        if (event.keyCode == Keyboard.UP || event.keyCode == Keyboard.W || event.keyCode == Keyboard.SPACE) {
            if (isTouchingGround()) {
                isJumping = true;
                yv = -100;
            }
        }
        if (event.keyCode == Keyboard.DOWN || event.keyCode == Keyboard.D) {
            if (xv == 0) {
                player.gotoAndPlay(275);
            }
        }
        if (event.keyCode == Keyboard.LEFT || event.keyCode == Keyboard.A) {
            if (xv == 0) {
                xv = -24;
            } else if (xv != -120) {
                xv-=2;
            }
        }
        if (event.keyCode == Keyboard.RIGHT || event.keyCode == Keyboard.D) {
            if (xv == 0) {
                xv = 24;
            } else if (xv != 120) {
                xv+=2;
            }
        }
    }
    

    Something else you may notice is that when the UP key and RIGHT key are both being held down, the computer seems to freeze keyboard input, however when the W key and D key are being held down you can still press other keys and the computer will register their input. The answer to that question is here.

    Update:

    For the fluid part, instead of triggering something when a keystroke takes place, it is better to have a boolean variable such as keyUP or UP that holds a true if the key is down or false when the key is up. Then have a function onEnterFrame(event:Event):void {} that performs an action when keyUP is true. Like so:

    import flash.events.*;
    
    public class keyEvents extends MovieClip {
        private var keyRIGHT:Boolean = false;
    
        public function keyEvents():void
        {
            this.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
            this.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
            this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }
    
        function onKeyDown(event:KeyboardEvent):void
        {
            if(event.keyCode == Keyboard.RIGHT) {
                this.keyRIGHT = true;
            }
        }
    
        function onKeyUp(event:KeyboardEvent):void
        {
            if(event.keyCode == Keyboard.RIGHT) {
                this.keyRIGHT = false;
            }
        }
    
        function onEnterFrame(event:Event):void
        {
            if(this.keyRIGHT) {
                // This code is executed while the RIGHT arrow key is down.
            }
        }
    }
    

    If the above code does not work I think that your problem lies with your keyboard, not that it’s broken or anything but the way it was made might be messing things up.

    Let me know if this didn’t help and I’ll continue trying.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I want use html5's new tag to play a wav file (currently only supported

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.