是的,您需要做的是创建两个精灵,然后进行碰撞检测。有一种简单的方法可以做到这一点,而通过 box2d 有一种更复杂的方法。
简单的方法:
sprite1.collidesWith(sprite2);
如果两个精灵相互接触,它应该返回 true。
通过 Box2d,您将使用称为ContactListener的东西来检测碰撞。
ContactListener contactListener = new ContactListener()
{
@Override
public void beginContact(Contact contact)
{
}
@Override
public void endContact(Contact contact)
{
}
@Override
public void preSolve(Contact contact, Manifold oldManifold)
{
}
@Override
public void postSolve(Contact contact, ContactImpulse impulse)
{
}
};
Inside beginContact, you will want to do your code for randomizing the locations of the sprites again (or whatever other algorithm you want to employ). The other methods give you additional functionality, for example you can employ endContact when the two objects stop overlapping each other.
For more information and a detailed tutorial see: http://www.andengine.org/forums/tutorials/contact-listener-t5903.html