0
votes

I've tried using hitTestObject(), but that seems to require that I make the call using a specific instance, rendering it more or less useless unless I want to have dozens of objects making dozens of collision checks each frame, which just seems wasteful and annoying to implement.

Is there any way to do collision check based on class rather than instance?

Maybe Something equivalent to this: http://docs.yoyogames.com/source/dadiospice/002_reference/movement%20and%20collisions/collisions/place_meeting.html

Alternatively, is there any function that returns whatever a list of objects that share overlapping coordinates with the one I'm checking?

1

1 Answers

1
votes

If I'm understanding your question correctly, you have several objects of that same class that each need to check for collisions against each other?

Yes, you would have to go through each object and perform a collision check against the other objects. I suppose you could write a hitTestClass function yourself, but behind the scenes it would still be the same. As far as implementing it, it's not so bad:

for( var i:int = 0; i < asteroids.length -1; ++i )
{
    var a:Asteroid = asteroids[ i ];
    for( var j:int = i+1; j < asteroids.length; ++j )
    {
        var b:Asteroid = asteroids[ j ];
        var isColliding:Boolean = a.hitTestObject( b );
        //Code here to do whatever in the case of collision
    }
}

If computational speed becomes a concern, then there are broad-phase collision detection techniques to chunk down the time. Quad trees are one example.