IDAT102 – Flash Game – Hit Detection 0010-0015

I first inter grated simple collision detection into my masterLoop function.

for (var loop2=lag; loop2
if (ballP1.hitTestObject(getChildByName("myBall" + loop2))) {
trace('HIT');
}
}

An error occurred whenever it was testing against a ball that doesn’t exist. I fixed this by adding “if (getChildByName((“myBall” + loop2)) != null)” so that it would only hit test against objects if it could find them.

for (var loop2=lag; loop2
if (getChildByName(("myBall" + loop2)) != null) {
if (ballP1.hitTestObject(getChildByName("myBall" + loop2))) {
trace('HIT');
}
}
}

Later the trace was replaced with:

var currentBall = getChildByName("myBall" + loop2).name;
removeChild(getChildByName(currentBall));

As well as this scoring was added.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.