-
Collision with 5 different objects
Hello I've got a simple function checking the collision between one object to four others. I'm pretty sure I made it work earlier today but it doesn't anymore, I'm utterly perplexed by this.
Code:
if(square, edge1, edge2, edge3, edge4.hitTestObject(Circle)){
gotoAndStop(46);
removeChild(Circle);
removeEventListener(MouseEvent.MOUSE_DOWN,mousePress);
removeEventListener(Event.ENTER_FRAME,doAll);
}
It only collides with the square, which is the first object stated.
I've tried using one of these "checks" for each object but that doesn't work either.
Is the code faulty in any way, or is there another solution to this?
Thanks in advance
-
Total Universe Mod
You have to run a hit test on each object in question using the or (||) operator
if(square.hitTestObject(Circle) || edge1.hitTestObject(Circle) || edge2.hitTestObject(Circle) ... etc.
Yes there are better ways to do it but it's somewhat involved. I highly recommend the book "Making Things Move" - AS3 edition by Keith Peters.
-
You could also use a For each statement to run a hit test for each item.
Code:
for each (var item in [square,edge1,edge2,edge3,edge4]) {
if (item.hitTestObject(Circle)) {
gotoAndStop(46);
removeChild(Circle);
removeEventListener(MouseEvent.MOUSE_DOWN,mousePress);
removeEventListener(Event.ENTER_FRAME,doAll);
}
}
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
|