当玩家在几秒钟后走过那个特定的瓷砖时,我想在我的瓷砖地图上掉下一块瓷砖。我该怎么做?
编辑: 我正在开发一款2D平台游戏...我希望当玩家在平台上跳跃时,该平台会在指定时间后跌落。
我为每个磁贴添加自定义属性。 TMX文件:
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" renderorder="right-down" width="50" height="50" tilewidth="30" tileheight="30" nextobjectid="1">
<tileset firstgid="1" name="8246060_orig" tilewidth="30" tileheight="30" tilecount="495">
<image source="tile_image/8246060_orig.jpg" width="1000" height="459"/>
<tile id="41">
<properties>
<property name="spring" value="true"/>
</properties>
</tile>
<tile id="42">
<properties>
<property name="spring" value="true"/>
</properties>
</tile>
<tile id="43">
<properties>
<property name="spring" value="true"/>
</properties>
</tile>
</tileset>
<tileset firstgid="496" name="26078133-tile-set-platform-for-game" tilewidth="30" tileheight="30" tilecount="120">
<image source="tile_image/26078133-tile-set-platform-for-game.jpg" width="450" height="257"/>
<tile id="38">
<properties>
<property name="winter" value="true"/>
</properties>
</tile>
<tile id="39">
<properties>
<property name="winter" value="true"/>
</properties>
</tile>
<tile id="40">
<properties>
<property name="winter" value="true"/>
</properties>
</tile>
</tileset>
<layer name="Tile Layer 1" width="50" height="50">
<data encoding="base64" compression="gzip">
H4sIAAAAAAAAC+3RwRGAIAADwUARYg1q/9VQjJTAS4dhH/vP5HpJOgAAALCkoyZtOOv/W3Z0JbmHJ3Nt9Pruf/wPAAAAwJ5e255BJRAnAAA=
</data>
</layer>
GameScene:
try {
mTmxLoader = new TMXLoader(activity.getAssets(),
engine.getTextureManager(), TextureOptions.NEAREST, vbom);
mTmxLoader = new TMXLoader(activity.getAssets(), engine.getTextureManager(), TextureOptions.BILINEAR_PREMULTIPLYALPHA, vbom, new ITMXTilePropertiesListener() {
@Override
public void onTMXTileWithPropertiesCreated(final TMXTiledMap pTMXTiledMap, final TMXLayer pTMXLayer, final TMXTile pTMXTile, final TMXProperties<TMXTileProperty> pTMXTileProperties) {
if(pTMXTileProperties.containsTMXProperty("spring", "true")) {
final Rectangle rect=new Rectangle(??);//How do I get the coordinates of a platform
final FixtureDef boxFixtureDef = PhysicsFactory.createFixtureDef(0, 0, 1f);
Body body=PhysicsFactory.createBoxBody(physicsWorld, rect, BodyType.StaticBody, boxFixtureDef);
rect.setVisible(true);
attachChild(rect);
body.setUserData("spring");
}
else if(pTMXTileProperties.containsTMXProperty("winter", "true")){
}
}
});
contactListener:
if (x1.getBody().getUserData().equals("spring")
&& x2.getBody().getUserData().equals("player")) {
engine.registerUpdateHandler(new TimerHandler(0.4f,
new ITimerCallback() {
public void onTimePassed(
final TimerHandler pTimerHandler) {
pTimerHandler.reset();
engine.unregisterUpdateHandler(pTimerHandler);
x1.getBody().setType(
BodyType.DynamicBody);
}
}));
}
答案 0 :(得分:1)
使用Box2D并创建动态实体。当你想要删除那个身体时(几秒钟后)就消灭它的身体