Reputation: 31
I have collision code which detects if i hit many walls, but when i move to another frame even though my walls are removed its like the collision is still there.
I think if i somehow stop the code when i enter the next frame it could help.
Also i am new at this.
This is my code.
function myHitTest(obj:DisplayObject, arr:Array):Boolean {
for (var i:int = 0; i < arr.length; ++i) {
//for (var item:DisplayObject in arr) {
var item:DisplayObject = arr[i]
if (obj.hitTestObject(item)) {
return true;
}
}
return false;
}
var everywall:Array = [w1,w2,w3,w4,w5,w6,w7,w8,w9,w10,w11,w12,w13,w14,w15,w16];
Upvotes: 0
Views: 556
Reputation: 1617
Another option that is also not the best way I'm sure but should work would be to add an if statement before that checks what frame you are on. Something like the following:
function myHitTest(obj:DisplayObject, arr:Array):Boolean {
// Check to see if the frame is the one I want the code to run on (1)
if(currentFrame == 1) {
for (var i:int = 0; i < arr.length; ++i) {
//for (var item:DisplayObject in arr) {
var item:DisplayObject = arr[i]
if (obj.hitTestObject(item)) {
return true;
}
}
}
return false;
}
currentFrame
is a keyword that you can just use if you are looking for the root's currentFrame. If you want a particular MovieClip
you can use MovieClip.currentFrame
. Change the ==1 to == whatever frame you want this to run on.
Upvotes: 1
Reputation: 10325
You can cheat, and simply st everywall = [];
. This will no longer check collisions with any of the 16 walls.
Buuut that's not addressing the primary issue. The important thing in this case is that something is still calling myHitTest
. Whatever loop is calling that needs to exit, or whatever callback is calling it needs to be refactored. If you need more than those hints, provide more code.
Upvotes: 2