我试图调整this HaxeFlixel教程,以使其更有趣,并学习如何在此过程中制作游戏。我正在做的第一件事就是限制移动到瓷砖。
然而,我已经走到了尽头 - 我所尝试的一切都没有奏效。我已经用以下内容替换了Player类中的movement()
函数的内容(作为参考,每update()
调用一次):
if (FlxG.mouse.justReleased) {
var _path:FlxPath;
_path = new FlxPath(this, Reg.mWalls.findPath(getGraphicMidpoint(), FlxG.mouse.getWorldPosition()), speed);
}
(Reg.mWalls
是我移动PlayState._mWalls
以使其可以访问此代码的位置。)
根据文档,这应该创建一个FlxPath并立即开始(因为第一个参数不是null
),而是它产生了这个错误:
Null Object Reference
Called from openfl._v2.display.Stage.__pollTimers (openfl/_v2/display/Stage.hx line 1020)
Called from openfl._v2.display.Stage.__checkRender (openfl/_v2/display/Stage.hx line 317)
Called from openfl._v2.display.Stage.__render (openfl/_v2/display/Stage.hx line 1035)
Called from openfl._v2.display.DisplayObjectContainer.__broadcast (openfl/_v2/display/DisplayObjectContainer.hx line 280)
Called from openfl._v2.display.DisplayObject.__broadcast (openfl/_v2/display/DisplayObject.hx line 174)
Called from openfl._v2.display.DisplayObject.__dispatchEvent (openfl/_v2/display/DisplayObject.hx line 195)
Called from openfl._v2.events.EventDispatcher.dispatchEvent (openfl/_v2/events/EventDispatcher.hx line 100)
Called from openfl._v2.events.Listener.dispatchEvent (openfl/_v2/events/EventDispatcher.hx line 270)
Called from flixel.FlxGame.onEnterFrame (flixel/FlxGame.hx line 493)
Called from flixel.FlxGame.step (flixel/FlxGame.hx line 648)
Called from flixel.FlxGame.update (flixel/FlxGame.hx line 700)
Called from flixel.FlxState.tryUpdate (flixel/FlxState.hx line 155)
Called from PlayState.update (PlayState.hx line 125)
Called from flixel.group.FlxTypedGroup.update (flixel/group/FlxTypedGroup.hx line 89)
Called from Player.update (Player.hx line 47)
Called from Player.movement (Player.hx line 59)
Called from flixel.tile.FlxTilemap.findPath (flixel/tile/FlxTilemap.hx line 794)
Called from flixel.tile.FlxTilemap.computePathDistance (flixel/tile/FlxTilemap.hx line 1802)
Called from *._Function_1_1 (openfl/_v2/display/Stage.hx line 124)
AL lib: (EE) alc_cleanup: 1 device not closed
答案 0 :(得分:0)
我最终自己解决了这个问题。
事实证明,我没有为拼贴0(空白拼贴)设置任何碰撞数据,而且我的地图上到处都是没有拼贴的斑点,因为它们在“外面”。
修复方法是使用方块0填充空白区域并将其添加到PlayState.create()
:
Reg.mWalls.setTileProperties(0, FlxObject.ANY);