PDA

View Full Version : hit test problem



bsw2112
January 8th, 2004, 01:46 PM
hello
i am in the process learning actionscript (have some knowledge of other web languages)
so i thought i could apply what i read and make a small game
that mimics an old game called grog. (game is far from finished but i already ran into problems)

http://www.wawryn.com/flash/game1.3.html

(you need to click on the flash to make it active and then moving the arrow keys you can make the man move and catch the apples.
if you press up or down the man will go back to his regular stance)

the problem is that the apples disapear before they hit the man.
I read on macromedia that the hittest is performed around the the symbol (binding box)

i would like to make the apple only disappear when it touches the man not the binding box. Can I do this?

if not i guess i could make a few smaller rectangles(than will wrap around the man's shape...but i find that my request is pretty strainght forward and there should be a way in flash to get around this) and put hittest on them

any help would be appreciated

ps i will post the actionscript when i get home since i am at work and don't have flash here

another problem is that when the man changes direction, there is a pause...why is that, is it possible because i go to a different frame in the mc to make the man face the opposite way?

thanks
bsw

bsw2112
January 14th, 2004, 10:52 AM
does anybody know how to make the hit test more efficient? :(

my code

***********************************
//in frame 1 of time line

appleNum = 1;

x= setInterval(createApple, 1000, this);

function createApple() {
_root.apple.duplicateMovieClip("apple" + appleNum,appleNum);
appleNum++;
}


//in my man1 mc

onClipEvent (keyDown) {
var keyCode;
keyCode = Key.getCode();
switch (keyCode) {
case 37 :
this._x = this._x-15;
gotoAndStop(3);
break;
case 39 :
this._x = this._x+15;
gotoAndStop(2);
break;
default :
gotoAndStop(1);
}
}



// in the apple mc (which is the master apple off the screen, instance called apple

onClipEvent (load) {
if (this._name != "apple") {
posX = random(450)+50;
posY = 0;
this._x = posX;
this._y = posY;
x = setInterval(moveIt, 75, this);
}
function moveIt(appleParam) {

appleParam._y += 8;
if (appleParam.hitTest(_root.man1)) {
// trace(apple1._name);
removeMovieClip(appleParam);
}

if (this._y>390) {
removeMovieClip(appleParam);
}
}
}

***********************************

ScriptFlipper
January 14th, 2004, 11:21 AM
try searching on "hittest" or "precise hittest" here on the forums

bsw2112
January 14th, 2004, 02:17 PM
opps, ya i guess i should have searched the forum and not the search/textbox feature on top of this page...
which points to a tut that does what i already have.

cheers and thanks for the reply

bsw