Results 1 to 6 of 6
Thread: AS3 HitTest
-
August 15th, 2007, 09:10 AM #17Registered User
posts
AS3 HitTest
Can someone please explain to me how to hitTest multiple objects which are all from the same movieclip. In this case bullets.
I know that the hitTest always effects the newest bullet created, but I don't now how to make it effect the "old" bullets aswell. I heard you have to use arrays, but I know nothing about them
Plus all the tutorials I find about this are for AS2.
So I would be truely greatful if someone gives me an example from how make an array for the bullets correctly to hitTesting, or give me a link to a tutorial.
Thanks in advance
-
August 15th, 2007, 10:46 AM #2131Registered User
posts
-
August 15th, 2007, 01:34 PM #3
...it should be that big
alright what you do is you create a function that pushes newly created bullets's (name all different but systematically ie bul_1, bul_2) then when the bullet leaves the stage take it out of the array, or when it gets blown up. then in a ENTER_FRAME event, you loop thur the array and check hit test for each bullet, this way if you have a fast gun and stuff there should only be like 10 hittest a frame, this method is very easy to implement and very functional
-
August 15th, 2007, 03:24 PM #47Registered User
postsFirstly, how do you make the bullet names automaticly create a number after their name systematic 1,2,3,4....
Secondly, how do you hitTest an array, is it like so:
(bullets is an array in the GameEngine package)
(This if statement is also in the Enemy01 package)
if (this.hitTestObject(GameEngine.bullets[bullet01]))
{
trace("ouch")
}
-
August 15th, 2007, 04:16 PM #57Registered User
postsDon't worry, someone on another forum gave me the code that I needed to figure it out:
var bulletArray:Array = new Array();
var bullet = new bullet();
bulletArray.push(bullet);
...
for(var i=0; i<bulletArray.length; i++) {
if(someThing.hitTestObject(bulletArray[i ]) {
//do something;
}
}
Thank you ajcates and Enix591 anyway.
-
August 16th, 2007, 09:41 PM #6
ok i had code that systematically named objects, i lost it tho, if i find it ill post it. but till then that code will work great

Reply With Quote


Bookmarks