Groups | Blog | Home
all groups > flash actionscript > november 2004 >

flash actionscript : using the hitTest action



blindRKside
11/13/2004 8:11:09 PM
i am making a game with a character you can move around with the arrow keys and
is contained inside a room

the problem is that i cant get the character to stay inside the room

someone told me to use th hitTest code and i tried it but i wasnt sure where
to place the code (on the character, wall, or frame)

Here is a copy of the code for u to see :

// You want to go left ...
if (hero.hitTest(leftWall)) {
// Hero has struck the wall
hero._x+= hero._width / 2;
// Moves hero to the right by one half of hero's width
// This would make a "bouncing" effect
} else {
// Hero has not struck the wall, so ...
hero._x-= 5;
// Keep moving hero left by 5 pixels
}


with this code, i am not sure how to incorporate each arrow key with it moving
the character aswell as keeping him from hitting a wall. but the code didnt
even stop him from going through the wall which leaves me back at the beginning.

you can see how far i am a http://www.geocities.com/jmkrmathis

thanks for any help,

blindRKside



kglad
11/13/2004 9:00:25 PM
if that code executes after hero has moved left and if that code is attached to
a frame and if hero doesn't move left "too" far (ie, past the wall), then it
would result in less of a leftward movement though i think you should probably
use:

hero._x=wall._x+hero._width; //and you may want wall._width, as well
AddThis Social Bookmark Button