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 7011119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:05:12+00:00 2026-05-27T22:05:12+00:00

I’m trying to make an HTML5 RPG game using easelJS to handle sprite animations.

  • 0

I’m trying to make an HTML5 RPG game using easelJS to handle sprite animations. When I press the arrow keys in any direction the character does not play the animation through, instead it seems to jump back to frame 0 and stop instead of looping the animation.

What I need is the animation to continue looping while the key is being pressed down, instead the character get’s stuck in a frame.

Here is the game I have so far, it’s really a mess because I’m experimenting and still learning HTML5.
http://cloudrealms.com/dev/

Here is the code that I am using:

Arrow Key capture:

      $(window).keydown(
        function(e){
            keys[e.which] = true;
            if(isMovementKey(e.which))
            {
                moveOrder.unshift(e.which);
                jQuery.unique(moveOrder);
                animationsToPlay.push(1);
            }
            e.preventDefault();
            return false;
        }
    );
    $(window).keyup(
        function(e){
            keys[e.which] = false;
            if(isMovementKey(e.which))
            {
                moveOrder.splice(jQuery.inArray(e.which, moveOrder),1);
            }
        }
    );

In my tick I have a function called HandleInput() here is the code:

function HandleInput()
{
    switch (moveOrder[0]) {
        case 38:  /* Up arrow was pressed */
            playerSequence[playerID].gotoAndPlay("walk_up");
            playerSequence[playerID].y -= playerSequence[playerID].vY;
        break;
        case 40:  /* Down arrow was pressed */
            playerSequence[playerID].gotoAndPlay("walk_down");
            playerSequence[playerID].y += playerSequence[playerID].vY;
        break;
        case 37:  /* Left arrow was pressed */
            playerSequence[playerID].gotoAndPlay("walk_left");
            playerSequence[playerID].x -= playerSequence[playerID].vX;
        break;
        case 39:  /* Right arrow was pressed */
            playerSequence[playerID].gotoAndPlay("walk_right");
            playerSequence[playerID].x += playerSequence[playerID].vX;
        break;
    }
}

What I want to know is how can I animate the player sprite while the arrow key is being held down?

  • 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-05-27T22:05:12+00:00Added an answer on May 27, 2026 at 10:05 pm

    It is a little confusing, and its hard to tell what your code is doing, could you provide a link?

    In terms of getting your player to move while the key is down I can offer a few pieces of advice. The way the onkeydown events work is that as long as the key is down, the event will be fired.

    If I were you, I would have a boolean that represents whether or not they key has been pressed. On the keydown event, you set it to true, on the keyup event you set it to false.:

    $(window).keydown(
        function(e){
            bool_keyDown = true;
        }
    );
    $(window).keyup(
        function(e){
            bool_keyDown = false;
        }
    );
    

    Note this works for any key, you will have to specify which you want in the keydown function, but you can leave it generic in the keyup function. In your ticker you check whether it is true. In the event that it’s true, you run the gotoandplay functionality on your spritesheet:

    function HandleInput()
    {
        if(bool_keyDown) 
            playerSequence[playerID].gotoAndPlay("walk_up");
    }
    

    This is not specific to any one key. So you might want to change it from a bool to a string. Maybe have the strings “up”, “down”, “left”, “right”, etc. , and null for no key pressed. Hope this helps.

    –Ashley

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

Sidebar

Related Questions

I am using Paperclip to handle profile photo uploads in my app. They upload
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
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

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.