drpelz
drpelz

Reputation: 811

pixel perfect collision + blitting

I'm using a blitting engine that uses bitmapData. No display objects.

Is there a fast pixel perfect collision detection available for such a game system?

I already tried CDK but that didn't work because it assumes you have display objects which my objects don't use. Sometimes my objects are pretty big and hitTest sucks in this case. I already tried circle-to-circle collisions but that didn't do the trick either. Any help or hints?

Update:

 public function renderTile(canvasBitmapData:BitmapData):void
    {
        x = nextX;
        y = nextY;

        point.x = x;
        point.y = y;

        if (animationCount >= animationDelay)
        {
            animationCount = 0;

            if(reverse)
            {
                currentTile--;
                if (currentTile < 1)
                {
                    currentTile = tilesLength - 1;
                }
            } else {
                currentTile++;
                if (currentTile == tilesLength)
                {
                    currentTile = 0;
                }
            }

        } else {
            animationCount++;
        }

        canvasBitmapData.lock();    
        tileRect.x = int((currentTile % spritesPerRow)) * tileWidth;
        tileRect.y = int((currentTile / spritesPerRow)) * tileHeight;
        bitmapData = new BitmapData(tileWidth - oversize, tileHeight - oversize, true, 0x000000);

        canvasBitmapData.copyPixels(tileSheet, tileRect, point);
        canvasBitmapData.unlock();
    }

Calling hitTest:

if (player.bitmapData.hitTest(player.point, 255, tempAsteroid.bitmapData, tempAsteroid.point, 255))

Currently the collisions do not work at all. I can fly through my objects and I get absolutely no collisions. I read somewhere that flash player standalone v10.1 had issues with bitmapData.hitTest but I'm using 10.3 so this should be not the problem.

Upvotes: 0

Views: 850

Answers (1)

Josha
Josha

Reputation: 599

Can not post comments (yet); so have to do it via answer.

It is not very clear how the two code snippets are related. Only thing I see is that in the first code snippet bitmapData gets created, but is not used or filled with anything.

So hitTest would always fail I guess, since bitmapData exists of only transparent pixels.

Following example shows hitTest seems the way to go though (no idea about speeds): http://www.mikechambers.com/blog/2009/06/24/using-bitmapdata-hittest-for-collision-detection/

Upvotes: 1

Related Questions