|
-
hitTest repeating ...
I have several objects in a separate movie and want to perform a hitTest with them and my other object 'knexman' which is noted below in the script.
Basically what's happening is that when I trace the output of the hitTest, it increments about 5 or 6 at a time with each enemy collision running into the knexman object. All I want to do is when objects run into the 'knexman', to increment and trace it by one. Once I get it to increment by one I can accurately conditionalize how many lives are left etc.
onClipEvent (load) {
function reset(){
this._y=0;
this._x=random(600)+300;
enemySpeed=random(15)+5;
this.gotoAndStop(1);
}
reset();
}
onClipEvent (enterFrame) {
this._y+=enemySpeed;
if (this._y>800) {
reset();
}
hitting = false;
cntr = 0;
if (_root.knexman.hitTest(_x, _y, true))
{
if (!hitting)
{
cntr = 1;
trace(cntr);
hitting = true;
_root.remove_life_from_stage("life", --_root.tries_remain);
_parent.knexman.gotoAndPlay(145);
}
else
{
hitting = false;
}
}
}
Last edited by justinc; 10-25-2010 at 06:59 PM.
JC
-
Senior Member
Im not sure how to implement it into whatever you've got going..
but if you asking about how to check to see if 1 'main' object is doing a hitTest() with any '1' of many objects on the stage..
let me ask..
what/when is the event you want to be checking for this hit test?
constantly? as soon as the movie loads? on a mouse click? after you drag -n- release some thing?
and basically you would add/have all the other 'objects' on the stage to an array...and then loop through the array checking to see it you hit test any of them.
-
You're making the hitting variable false at the wrong spot. Try this instead:
Code:
if (_root.knexman.hitTest(_x, _y, true)){
if (!hitting){
cntr = 1;
trace(cntr);
hitting = true;
_root.remove_life_from_stage("life", --_root.tries_remain);
_parent.knexman.gotoAndPlay(145);
}
}else{
hitting = false;
}
-
re: hitTest repeating..
I'm performing the check in a movie called enemy1 which contains the onClip event handling actionscript to perform the hitTest. the movie clip enemy1 has many objects on the stage that collide with my subject called 'knexman'. I'm checking as soon as movie loads, or until one of the many objects hits the k'nexman. Then when '1' hit occurs make it do something. But like I said, my main issue is when the 'many' objects fall onto the knexman for collide check, the incremental trace comes at more than a 1 increment value. Let's say one of my enemy objects collides with the knexman. The trace will show a 1, 1, 1 for just 1 collide....when I'm aiming to just output '1'.
-
Look at what you have, stripped down this is what I see:
Code:
if(!hitting){
hitting = true;
}else{
hitting = false;
}
so it will always alternate between true and false.
-
re: hitTest repeating..
Yeah I do see that. Any work around?
-
I showed you already. Just move it down one braket so that it does else for the hittest instead of the contained if statement.
-
the hitTest is still incrementing 5 at a time with each passing collide of the enemy object. :-(
Actionscript Code:
onClipEvent (load) {
function reset(){ this._y=0; this._x=random(600)+300; enemySpeed=random(15)+5; this.gotoAndStop(1); }
reset();
}
onClipEvent (enterFrame) { this._y+=enemySpeed; if (this._y>800) { reset(); }
hitting = false; cntr = 0;
if (_root.knexman.hitTest(_x, _y, true)){ if (!hitting){ cntr = 1; trace(cntr); hitting = true; _root.remove_life_from_stage("life", --_root.tries_remain); _parent.knexman.gotoAndPlay(145); } } else { hitting = false; } }
-
The second problem is you are having hitting = false every frame. Move that line of code from above cntr = 0; to onClipEvent(load) Then it will work fine.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|