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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:23:23+00:00 2026-05-23T14:23:23+00:00

Am making a simple flash game and am trying to keep the avatar from

  • 0

Am making a simple flash game and am trying to keep the avatar from hitting walls in a given level, here is the code I wrote, its simple enough

       var hitWall:Boolean = checkWallHitlvl1();



        if ( downKeyIsBeingPressed  )
            {
                avatar.moveABit( 0, 1 );
                if(hitWall)
                {
                    avatar.moveABit( 0, -5);

                }

            }
            else if ( upKeyIsBeingPressed  )
            {
                avatar.moveABit( 0, -1 );
                if(hitWall)
                {
                    avatar.moveABit( 0, 5 );

                }

            }   
            else if ( leftKeyIsBeingPressed  )
            {
                avatar.moveABit( -1, 0 );
                if(hitWall)
                {

                    avatar.moveABit( 5, 0 );


                }

            }
            else if ( rightKeyIsBeingPressed )
            {
                avatar.moveABit( 1, 0 );
                if(hitWall)
                {
                    avatar.moveABit( -5, 0 );

                }

            }   

hitWall checks if the avatar hits the level’s walls, the problem with this code is that even if for say I hit a wall from the right, and am trying to move left, I cant since hitWall doesn’t check from where the wall is hit, my question is is there a way to make this work without actually needing to figure out from which direction the player hits a given wall, i tried moving the avatar automatically to the left if he hits it from the right, but it didn’t quite work out so well…

any suggestions please?

thanx =D

EDIT1: i edited the code, it works now, but it looks kinda jerky since i have to step backwards 5 pixels, I cannot step backwards 1 pixel unfortunately since, since flash’s hitTestObject still returns true (checkWallHitLvl1() basically uses hitTestObject to check if the player hits the wall), any suggestions?

EDIT2: i found a way to fix it, just need to run some more tests and make sure it works fine, if they all pass i will post the code up, basically I just used 4 boolean variables to check which direction i hit the wall, and went from there…=D

  • 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-23T14:23:23+00:00Added an answer on May 23, 2026 at 2:23 pm

    What I do is keep the position of when it is not hit.

        if ( downKeyIsBeingPressed  )
            {
                avatar.moveABit( 0, 1 );
                if(hitWall)
                {
                    avatar.moveTo(safeX, safeY);
    
                } else {
                    safeX = x;
                    safeY = y;
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple platform game in Flash CS5 and Actionscript 3.0. When the
I am making a simple game in order to learn a new language. I
I'm making a simple 2 player game in XNA and started looking into saving
If I'm making a simple grid based game, for example, I might have a
I'm making a simple 2D game for the iPhone. It's based on CrashLanding. so
I'm making a simple Image Debugger Visualizer. Code is below. I'm not sure if
I am making simple graphical game in WinForms and currently I would like to
I'm making a Flash game which will be up on Facebook, I'm using Python/Django
I'm making a binary socket server for Flash and I'm trying to figure out
I must be making a simple mistake (new to Flex). Here is main.mxml: <?xml

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.