-
hitTest with duplicated movieClips
Hey I'm stuck!
I am making a shooter game and the bullets are duplicated movieClip and the monsters are also duplicated movieClips so how do you do hitTest with them? I can do it with one duplicated movieClip and then other static clips cause I can put this.hitTest(monster) but what if the monster also has a dynamic name?
Hugs for any help on this
-
I am having to solve the same kind of issue in a game I am making. I am probably going to use an array to store the names of all my duplicated movieClips. As duplicates are created, incremental names for them will be pushed to an array. Then my collision detection script will use all the names in the array to check for collisions.
Don't have any examples to show, as I have yet to write any of the duplicate Clip code.. In theory is should hopefully work though.
Steve
-
nevermind
this is prolly a dumb way but i fixed it. i figured there aint no more than 10 bullets at a time so they get named based on a variable that goes 0-9 so then i have the mosters onEnterFrame do a hitTest that loops through the 10 bulletNames. Prolly inefficient but it works. Now the problem is that when they do detect a collision the this.removeMovieClip(); don't work. anybody know how to fix that? Here's the code for the fix on the both dynamic clips hit detection:
Code:
onClipEvent (enterFrame) {
if (this.inner._currentframe<20) {
for (i=0; i<11; i++) {
if (this.hitTest(_root["spray"+i])) {
this.inner.gotoAndPlay("sparkle");
}
}
}
if (this.inner._currentframe>30) {
_root.bar.score += random(70);
_root.bar.stinkies -= 1;
this.removeMovieClip();
}
}
The this.removeMovieClip(); isn't work. do you know why?
-
yeah flashpowder thanks. I was thinking using arrays too but cause I figured there wern't going to be that many bullets I just got lazy and made a loop for it hahaha.
any idea why this.removeMoveClip(); don't work?
-
var x:Number = 1; x /= 0;
For some reason, a movie clip cannot remove itself. I have no idea why.
-
removing movieClip
you can!! I just learned that for this.removeMovieClip(); to work it needs a positive depth! Now it works great! here's the code:
Code:
this.swapDepths(300);
removeMovieClip(this);
-
oh crap FlashPowder. My way above is buggy hahaha crap! you gotta use an array it seems cause like say bullet 6 hits and removes itself the bulletCount variable that is the 0-9 number to add to their name don't know which one to say. arrrghh. alright imma try the array way and if i get it working i'll post it back here arrrghhh. unless you did it already hint hint wink wink
-
var x:Number = 1; x /= 0;
Awesome! That should help me a lot! I've been trying to find a way to do that for a long time now!
-
I won't be writing my code until sometime this week probably, so won't have anything for a few days.. It seems though, that the array method is probably the best solution.
-
man I'm close but I can't get the hitTest part to work! arrghh. The arrays work great and I splice the bullets and monsters out no problem when their animation is done but as far as hitting each other one little thing is off. In the output I traced their names and it's working so I donno why the hitTest part isn't working here's the code:
Code:
for (i=0; i<sArray.length; i++) {
var sprayi = sArray[i];
for (j=0; j<mArray.length; j++) {
var monst = mArray[j];
trace("hitTest Names: "+[monst]+", "+[sprayi]);
if ([monst].hitTest(sprayi)) {
trace("HIT!!! "+monst+", "+sprayi);
}
}
}
Anybody see why the hitTest part might not be working? Might be sompin simple. thanks!
-
fixed!!!
you gotta use _root up in that *****. Here's the code:
Code:
for (i=0; i<sArray.length; i++) {
var sprayi = sArray[i];
for (j=0; j<mArray.length; j++) {
var monst = mArray[j];
if (_root[sprayi].hitTest(_root[monst])) {
trace("HIT!!! "+monst+", "+sprayi);
}
}
}
it is working but I haven't tested it enough to put a RESOLVED for this thread yet. but I will once it's perfect. thanks again everybody and i'll post more code here later on this.
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
|