简体   繁体   English

Slick2D:getTileProperty不应返回true

[英]Slick2D: getTileProperty returns true when it shouldn't

I'm trying to implement some collision detection to a test game i've been making. 我正在尝试对我一直在做的测试游戏实施一些碰撞检测。 I've used TiledMap to create the map and set a property on one of the tiles to blocked=true This tile is then drawn on layer 0. 我使用TiledMap创建地图,并将其中一个图块的属性设置为blocked = true,然后在第0层上绘制了该图块。

I then check to see if the tile exists in the direction the player is moving, using the following code 然后,我使用以下代码检查图块是否存在于玩家移动的方向上

if (input.isKeyDown(Input.KEY_DOWN)) {
    sprite = down;
    sprite.update(delta);
    int tileID = map.map.getTileId((int) x / map.map.getTileWidth(), (int) y / map.map.getTileHeight() + 1, 0);
    String value = map.map.getTileProperty(tileID, "blocked", "false");
    if (value.equals("true")) {
        y += delta * 0.1f;
        System.out.println("Tile ID: " + (int) (x / map.map.getTileWidth()) + ", " + (int) (y / map.map.getTileHeight() + 1) + " Try to walk down. Tile value below the player is:" + value);
    }

}

This is repeated for each direction. 对于每个方向都重复此步骤。

The problem I'm running into is it's picking up the blocked property for incorrect tiles You can understand better with this video . 我遇到的问题是它正在拾取被遮挡的属性以获取不正确的图块。通过此视频可以更好地理解。 The yellow tiles are the collision/blocked tiles. 黄色图块是碰撞/阻塞图块。

I think you have this issue because you update the graphics outside your if statement 我认为您遇到了这个问题,因为您在if语句之外更新了图形

Try to move the ones below inside the if : 尝试将以下内容移至if

sprite = down; 
sprite.update(delta);

However I suppose one of these put the face of the sprite down and therefore should not be inside. 但是我想其中之一放下了精灵的面,因此不应该放在里面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM