0

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;
            }
        }
    }
}
2
  • @SamDeHaan Basically this code adds a 'bounding box' around the object which is a square, however, I don't want 'empty' parts of my movie clip to count as the collision. Commented Apr 27, 2012 at 12:55
  • If there's no way around this I think I'll create a small movie clip within the moveiclip and just have it at the end of the frog's tongue and use that instead of the whole frog. Commented Apr 27, 2012 at 13:05

3 Answers 3

2

Might I suggest trying out the fantastic Collision Detection Kit?

I'm sure it will do everything you need and more. It's also AS3 which is what your code sample is written in, so I hope you find it useful.

Sign up to request clarification or add additional context in comments.

1 Comment

I'll accept this as the answer since it's the best solution, although I'm doing this for coursework and can't really use that code unfortunately.
1

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.

Comments

0

If you're not allowed to use a third-party library for your coursework you should have a look at this excellent tutorial on pixel-level collision detection with ActionScript 3.0.

The general idea is that you create BitmapData copies of your vector graphics and use the hitTest method of that class to check for a collision at a pixel-level.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.