How to use TMX map object property to change objects behaviour

丶灬走出姿态 提交于 2019-12-12 03:56:50

问题


i am developing game in andEngine using Tiled maps in TMX map i have river object and i want player will be die after falling in river

but i have no idea how to implement this

I am only able to create wall objects using this code:

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);
                 }
             }
         }
    }

Thanks in advance


回答1:


Use the same code. In your TMX editor, create a new layer and add a property "danger" to it. You can then create any objects there (e.g. rectangles over your river tiles). Then add another 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/how-to-use-tmx-map-object-property-to-change-objects-behaviour

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!