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

The Archive Base Latest Questions

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

I am currently working on a nice little 2D game engine in AS3. You

  • 0

I am currently working on a nice little 2D game engine in AS3. You can even load in different flash movie clips through XML for the different animations. One of the features also allows you to flip an animation when you perform a certain action. That way you could have 1 animation for both left and right (as usual). I have the matrix transformation working correctly; however, I think my logic for flipping things back and forth is incorrect. The result is that the wrong animation will play at the wrong time. I decided to make the animation played based on the velocity of the moving object rather than on key press since I have physics elements involved.

Here is a link to the game in its current state: http://parrisstudios.com/Game_Design/gameEngineDemo/

The issue is mainly that animations play at incorrect times, or don’t play when they should.

Here is my code for the flipping (let me know what you guys think):
ps: the direction variable is the last direction the character is facing (left or right in this case, it is described later in the code)

private function drawJumpMode():void {
        var change:Boolean = false;
        //decide whether to swap graphics or continue playing

        if (Math.abs(particleGroup.particles[0].velocity.y) < epsilon && Math.abs(particleGroup.particles[0].velocity.x) < epsilon && direction == "right") {
            if (lastClipAction != "stillRight"){ 
                lastClipAction = "stillRight";
                change = true;
            }
        }
        else if (Math.abs(particleGroup.particles[0].velocity.y) < epsilon && Math.abs(particleGroup.particles[0].velocity.x) < epsilon && direction == "left") {
            if (lastClipAction != "stillLeft"){ 
                lastClipAction = "stillLeft";
                change = true;
            }
        }
        else if (particleGroup.particles[0].velocity.y > 0 && Math.abs(particleGroup.particles[0].velocity.x) < epsilon) {
            if (lastClipAction != "down"){ 
                lastClipAction = "down";
                change = true;
            }
        }
        else if (particleGroup.particles[0].velocity.y < 0 && Math.abs(particleGroup.particles[0].velocity.x) < epsilon) {
            if (lastClipAction != "up"){ 
                lastClipAction = "up";
                change = true;
            }
        }
        else if (particleGroup.particles[0].velocity.x > 0) {
            if (lastClipAction != "right") {
                lastClipAction = "right";
                direction = "right";
                change = true;              
            }
        }
        else if (particleGroup.particles[0].velocity.x < 0) {
            if (lastClipAction != "left"){ 
                lastClipAction = "left";
                direction = "left";
                change = true;
            }
        }

        //If the movie clip has changed, swap the old one back into the all clips library and get the new one.
        if (change) {
            //set flip to false whenever there is a change in movie clip
            flipped = false;
            //if the movie clip was flipped before, this should flip it
                            //back to normal
            flip();
                            //remove movie clip from the scene
            game.removeChild(playingMovieClip);
                            //check it back into the movie clip library
            allClips.addChild(playingMovieClip);
                            //add the movie clip into the scene
            playingMovieClip = MovieClip(allClips.getChildByName(actionToClip[lastClipAction + "Name"]));
            game.addChild(playingMovieClip);
        }

        //Flip if needed
        flip();

        //set it to true so that it won't be constantly flipped.
        flipped = true;

        //set movie clip to be center over the main particle
        playingMovieClip.x = particleGroup.particles[0].center.x;
        playingMovieClip.y = particleGroup.particles[0].center.y;
    }
private function flip():void {
        //If a transformation is required, then do so
        if (actionToClip[lastClipAction + "H"]=="1" && !flipped){
            flipHorizontal(playingMovieClip);
        }
        if (actionToClip[lastClipAction + "V"]=="1" && !flipped){
            flipVertical(playingMovieClip);
        }
    }
  • 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-12T18:27:10+00:00Added an answer on May 12, 2026 at 6:27 pm

    I believe the code in question is here.

                //If the movie clip has changed, swap the old one back into the all clips library and get the new one.
                if (change) {
                        //set flip to false whenever there is a change in movie clip
                        flipped = false;
                        //if the movie clip was flipped before, this should flip it
                            //back to normal
                        flip();
                            //remove movie clip from the scene
                        game.removeChild(playingMovieClip);
                            //check it back into the movie clip library
                        allClips.addChild(playingMovieClip);
                            //add the movie clip into the scene
                        playingMovieClip = MovieClip(allClips.getChildByName(actionToClip[lastClipAction + "Name"]));
                        game.addChild(playingMovieClip);
                }
    
                //Flip if needed
                flip();
    

    The problem is that you are doing a double flip here. This works find if you are in fact changing clips from the change. For example if you go from running right to standing right. It goes wrong when you go from running right to running left. Since they are the same clip just flipped you end up doing two flips in this situation. This causes the moonwalk behaviour :-).

    I would suggest cleaning up this logic and providing a way to reset the flipping. Instead of flipping back to the original orientation, reset back to it so you can guarantee the state of the clip.

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

Sidebar

Related Questions

I am currently working on a nice table that displays the items in a
So I'm just getting started with Python, and currently working my way through http://diveintopython3.ep.io/
Currently working on a nice three step order form for a wedding photographer, so
I'm currently working with the ASP.NET login control. I can set a custom failure
Currently working on a script to ping every host on a /24 subnet, and
currently working on generation elliptic curve for ECDSA and met some problems: An elliptic
Currently working in the deployment of an OFBiz based ERP, we've come to the
Currently working on a VBScript to automate some of the dirty PST ingestion work
Currently working on a site built in Django and i'm getting an issue when
Currently working with NSURLConnection. Found a great website showing important delegate methods coming with

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.