View Full Version : hitTest with many of same movieclips
VoS
January 26th, 2005, 11:10 AM
Hello there..
Im making a game in which you controll a turret and it spews out bullets like mad..
Usually i know you would name each dupicalted movieclip sumthing like
"movieclipname"+nextnumber
But i was in this case hoping i could name em all "bullet" for the simplicity of hittesting
using
bullet1.duplicateMovieClip("bullet1", this.getNextHighestDepth(), {_x:bx, _y:by, xs:Xmov, ys:Ymov});
to duplicate
and
if(this.hitTest(_parent.bullet1)){ // is an onEnterFrame
trace("wuuuuuuuuuu");
to c if anything is happening
nothing however happens, i am not ceeing the trace message..
Can i not have many movieclips named the same, or is there somethign else i need to consider
Thanks
JKosoy
January 26th, 2005, 11:33 AM
Naming movieclips the same is always a problem. Try something like this:
_global.count = 2;
var $bullet = bullet1.duplicateMovieClip("bullet_"+count, this.getNextHighestDepth(), {_x:bx, _y:by, xs:Xmov, ys:Ymov});
count += 1;
if(this.hitTest($bullet)...
then you create bullet2,bullet3,bullet4,etc...
VoS
January 26th, 2005, 12:02 PM
that dosent seem to be working (
onClipEvent (enterFrame) {
if(_root.$bullet.hitTest(this)){
trace("wuuuuuuuuuu");
}
}
var $bullet = bullet1.duplicateMovieClip("bullet_"+count, this.getNextHighestDepth(), {_x:bx, _y:by, xs:Xmov, ys:Ymov});
count += 1;
bullets are appearing perfectly , but its just not detecting a hit
VoS
January 26th, 2005, 12:07 PM
just a question .. does that way u describe work when there are about 30 different bullets at same time , will it check for all of em?
JKosoy
January 26th, 2005, 12:23 PM
No. I think I was a little confused with what you were trying to accomplish at first. I'll need some more time to flush out exactly how I think you should do this...I'm thinking you'll need to push each button you create into an array and then in your enterFrame loop thru the array for each button and check the hitTest...
VoS
January 26th, 2005, 12:34 PM
The way its set up right now is..
ive got a minigun turret positioned sumwere on the screen when it fires
this function is called
function shootbullet (bx,by,ang) {
//trace(totalTurret);
//trace("___bulletfired___");
qq=Math.round(Math.random());
if(qq==1){
ang2=ang+(Math.random()*accuracy);
}
if(qq==0){
ang2=ang-(Math.random()*accuracy);
}
ang=((ang2-180)*-1)/(180/Math.PI);
s=speed+(Math.random()*50);
Xmov = (s/56.5)*Math.cos(ang)*(180/Math.PI);
Ymov = (s/56.5)*Math.sin(ang)*(180/Math.PI);
_root.currdot=_root.currdot+1;
//bullet1.duplicateMovieClip("bullet1", this.getNextHighestDepth(), {_x:bx, _y:by, xs:Xmov, ys:Ymov});
var $bullet = bullet1.duplicateMovieClip("bullet_"+count, this.getNextHighestDepth(), {_x:bx, _y:by, xs:Xmov, ys:Ymov});
count += 1;
trace($bullet);
//bulletSound.start();
bulletsLeft=bulletsLeft-1;
chanceToJamReal=chanceToJamReal+(chanceToJamIncrea se/totalTurret);
}
and another building on the map has this
onClipEvent (enterFrame) {
if(_parent.$bullet.hitTest(this)){
trace("wuuuuuuuuuu");
}
}
that functions is being called at first once per about second
but as the game progresses it will eventually be called about 90 times per second
and i need all of these bullets to be triggering the hittest
(which is why i was hoping i could name em all the same thing)
and..
each bullet deletes itself after about 3 second of livetime, so they need to be removed from whatever array they are put into (im guessing thats only way to do it)
//VoS
[edit] my apologies if i was not clear enough
VoS
January 26th, 2005, 01:31 PM
I was thinking of an alternate solution to this..
Is there any way to return the variabel of instance name of whatever movieclip is currently colliding with the one your code is in..
so lets say i have instance 001 with the code that returns whichever movieclip is on top of it
and then you only check if the first few charactes mach , like if its called bullet_234234234 ud just check if bullet was part of its name
no idea if its possible , just a idea =)
VoS
January 29th, 2005, 11:31 AM
could you place all the bullets in one MC..
and use
this.hittest(bulletconatiner,true) // were true sets the shapeflah boolena to positive..
in that case im wondering why this code is not duplicating a bullet..
the code is on the main timeline of the mc, as a function
and im tracing out all the values so they are getting inside of the mc and into the function..
and the mc contains the MovieClip being duplicated
bullet2.duplicateMovieClip("bullet_"+count, this.getNextHighestDepth(), {_x:bx, _y:by, xs:Xmov, ys:Ymov});
heres all the code
the movie clip this is inside is at the root movies 0,0 location , so both should have same x y grid
function shootbullet (bx,by,ang) {
trace(bx+" "+by+" "+ang); // this statement is showing correct info
//trace(totalTurret);
//trace("___bulletfired___");
qq=Math.round(Math.random());
if(qq==1){
ang2=ang+(Math.random()*accuracy);
}
if(qq==0){
ang2=ang-(Math.random()*accuracy);
}
ang=((ang2-180)*-1)/(180/Math.PI);
s=speed+(Math.random()*50);
Xmov = (s/56.5)*Math.cos(ang)*(180/Math.PI);
Ymov = (s/56.5)*Math.sin(ang)*(180/Math.PI);
_root.currdot=_root.currdot+1;
//bullet1.duplicateMovieClip("bullet1", this.getNextHighestDepth(), {_x:bx, _y:by, xs:Xmov, ys:Ymov});
bullet2.duplicateMovieClip("bullet_"+_parent.count, this.getNextHighestDepth(), {_x:bx, _y:by, xs:Xmov, ys:Ymov});
_parent.count += 1;
//bulletSound.start();
bulletsLeft=bulletsLeft-1;
_parent.chanceToJamReal=_parent.chanceToJamReal+(_ parent.chanceToJamIncrease/_parent.totalTurret);
}
chup
January 29th, 2005, 02:18 PM
Just wonder..
can u have each bullet tracing ur target instead of the target tracing every bullet?
VoS
January 30th, 2005, 10:42 AM
Just wonder..
can u have each bullet tracing ur target instead of the target tracing every bullet?
if every bullet was to hitest for everything, the movie would perform poorly..
since the processor would not be abel to handel all of it..
But right now i think im onto a solution...
im placing all the created bullets into a movieclip , and them im gonna hittest for that movieclip..
i just have to figure out how "shapeflag" works
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.