简体   繁体   中英

how to make walls in actionscript 3.0?

i've been making a twist on the labyrinth game and i've got my ball to move with physics but im struggling with getting it to hit the walls around it. its currently a movie clip with black walls, and ive used this code to try and stop it:

if (character.hitTestObject(walls)){
        character.x = //something
        character.y = //something
    }

all this does is when it hits any part of the movie clip, (even the blank spaces) it moves my character,

is there any sort of code i can use to maybe detect hitting a certain colour?

One way you could do this, is to use hitTestPoint() method to test if any of the corners have hit your wall.

hitTestPoint() tests only a single location to see if that point collides with an object. This is how you could test the top left corner of your character to see if it's touching the wall :

// I am assuming that x,y is the top left corner of your character

if (wall.hitPointTest(character.x, character.y, true))
{
   // top left collided with wall
{

So you could do the same for all corners, or if you want, you can determine any collision points you want to check for the character.

Depending on your level of precision, this method might work just fine for your needs. But if you want pixel perfect collision, you can check out this link :

http://www.freeactionscript.com/2011/08/as3-pixel-perfect-collision-detection/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM