本文介绍了如何使用TMX地图对象属性来改变对象的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我在使用andEngine瓷砖地图开发游戏
在TMX地图,我有河流的对象,我想在河边下跌后玩家将模具

i am developing game in andEngine using Tiled mapsin 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

我只能透过这个code墙对象:

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

在此先感谢

推荐答案

使用相同的code。在你的TMX编辑器,创建一个新层,添加属性危险给它。然后,您可以创建(在你的瓷砖河例如矩形)有任何对象。然后添加其他如:

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

这篇关于如何使用TMX地图对象属性来改变对象的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 07:54