[英]HaxeFlixel tilemap collisions
I am developing a game in Haxe with the HaxeFlixel Framework. 我正在使用HaxeFlixel框架在Haxe中开发游戏。
I decided to split the map in chunks so i can load new areas of the map at runtime (without loading screen). 我决定将地图分成几部分,以便在运行时加载地图的新区域(不加载屏幕)。 For that i put every chunk in an instance of FlxTilemap
. 为此,我将每个块都放在FlxTilemap
实例中。
Now I noticed that, when i try to move a FlxTilemap
(by changing its x
and y
properties) the collision detection ( with FlxG.collide(hero, map)
) does not work right. 现在我注意到,当我尝试移动FlxTilemap
(通过更改其x
和y
属性)时,碰撞检测( with FlxG.collide(hero, map)
)无法正常工作。
To test why the collision detection doesn't work, I simply added a FlxTilemap
to the scene and collided it with my hero: 为了测试为什么碰撞检测不起作用,我只是向场景添加了FlxTilemap
并将其与我的英雄碰撞:
map = new FlxTilemap();
var mapData = "";
for (y in 0...8) {
for (x in 0...8) {
mapData += "0,";
}
mapData += "\n";
}
map.loadMap(mapData, AssetPaths.tuxemon_sprites__png, 16, 16);
for (x in 0...8) {
map.setTile(x, 6, SpriteSheet.TILES.FENCE.LOOSE_1_RIGHT);
}
for (y in 0...8) {
map.setTile(6, y, SpriteSheet.TILES.FENCE.LOOSE_1_RIGHT);
}
map.setPosition(
map.x - map.width / 2,
map.y - map.height / 2
);
add(map);
Collision detection is handeled in the update()
method of the state: 冲突检测在状态的update()
方法中处理:
override public function update():Void
{
super.update();
FlxG.collide(hero, map);
}
Am I doing it the wrong way or did I simply miss something? 我是用错误的方式做的还是只是错过了什么?
EDIT: 编辑:
There seems to be a problem in the HaxeFlixel collision detection. HaxeFlixel碰撞检测似乎存在问题。 The collision will only be detected when the x
and y
properties of the FlxObject
s are positive. 仅当FlxObject
的x
和y
属性为正时,才会检测到冲突。 I want to have negative x
/ y
positions as well. 我也想有负的x
/ y
头寸。
Does anyone know a fix or workaround for this problem? 有谁知道解决此问题的方法或解决方法?
Try changing the bounds of your world space. 尝试更改您的世界空间的边界。 Specifically, FlxG.worldBounds
. 具体来说,是FlxG.worldBounds
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.