我正在用andEngine开发游戏,使用TMX地图中的瓦片地图,我有河流对象,我希望玩家在落入河流后会死亡。
但是我不知道如何实现它
我只能使用以下代码创建墙对象:
private void createUnwalkableObjects(TMXTiledMap map)
{
// Loop through the object groups
for(final TMXObjectGroup group: this.mTMXTiledMap.getTMXObjectGroups())
{
if(group.getTMXObjectGroupProperties().containsTMXProperty("wall", "true"))
{
// This is our "wall" layer. Create the boxes from it
for(final TMXObject object : group.getTMXObjects())
{
final Rectangle rect = new Rectangle(object.getX(), object.getY(),object.getWidth(), object.getHeight());
final FixtureDef boxFixtureDef = PhysicsFactory.createFixtureDef(0, 0, 1f);
PhysicsFactory.createBoxBody(mPhysicsWorld, rect, BodyType.StaticBody, boxFixtureDef);
rect.setVisible(false);
mScene.attachChild(rect);
}
}
}
}提前感谢
发布于 2013-05-20 11:36:01
使用相同的代码。在您的TMX编辑器中,创建一个新层,并为其添加一个属性"danger“。然后你可以在那里创建任何对象(例如,河面上的矩形)。然后添加另一个if:
...
else if(group.getTMXObjectGroupProperties().containsTMXProperty("danger", "true"))
{
// This is layer with dangerous objects (river etc)
for(final TMXObject object : group.getTMXObjects())
{
// create sensor physics body and register collision detection
// on collision, make the user die
}
}https://stackoverflow.com/questions/16055059
复制相似问题