libGDX更改tilemap [英] libGDX change tilemap

查看:56
本文介绍了libGDX更改tilemap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用box2d制作2d角色扮演游戏.所以,我有一个问题.当我的一个身体(角色)与另一个(门)碰撞时,需要更改地图,我是否应该为地图创建新的屏幕并进行更改?还是有一个更简单的解决方案?

I am making an 2d rpg game with box2d. So, I've got a problem. When one of my bodies(the character) collides with another(a door) the map needs to change, should I just create new screens for maps and change them? Or is there a more simple solution?

推荐答案

您只能在同一屏幕上更改当前地图.您要做的是,假设您的地图变量名称为 testMap .现在,假设您的播放器刚撞到一扇门.现在,假设您将调用一个名为 changeMap()的方法.这是您将放入 changeMap()方法中的内容.(假设您使用的是平铺地图,则可以在此处相应地更改逻辑)

You can change your current map on the same screen only. What you have to do is, Let's say your map variable name is testMap. Now let's say your player just collided with a door. Now let's say you will call a method called changeMap(). Here is what you will put inside changeMap() method. (Assuming you are using tiled maps, you can change logic accordingly here)

void changeMap() {
    Gdx.app.postRunnable(() -> { //Post runnable posts the below task in opengl thread
        testMap = new TmxMapLoader().load("someMap.tmx"); //load the new map
        renderer.getMap().dispose(); //dispose the old map
        renderer.setMap(testMap); //set the map in your renderer
    });
}

这篇关于libGDX更改tilemap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆