Search code examples
actionscript-3flashactionscriptcollision-detectioncollision

ActionsScript 3 Collision


Frog

I'm developing a flash game called Frog, at the moment my code for collision between my frog and fly doesn't work as expected. I'd like to have it so it works something similar to the method linked below (last example).

Collision detection methods, hitTest and hitTestObject alternatives

Any help would be appreciated.

function hitTargetFunction():void {
    for (i = 0; i < insectsMC.length; i++) {
        for (j = 0; j < insectsMC[i].length; j++) {
            if (frogMC.hitTestObject(insectsMC[i][j])) {
                trace('Target: ' + insectsMC[i][j].name);
                score +=  1;
                trace('Score: '+score);
                insectsMC[i][j].x = 0 - insectsMC[i][j].width * 2;
            }
        }
    }
}

Solution

  • Creating a movieclip/sprite inside the frog movieclip will probably be the best thing for you in this situation. PixelPerfectCollision is very awesome and useful(however on larger games, expensive) but the collision would then be with any piece of the frog. You could of course break apart your frog movieclip and just do PixelPerfectCollision on just the tongue. But if this is for coursework I'd stick to just doing hitTest() on a display object of some kind inside the the frog.