我正在尝试调整这个HaxeFlixel 教程,以使其更有趣,并学习如何在此过程中制作游戏。我要做的第一件事就是限制瓷砖的移动。
然而,我遇到了困难——我尝试过的都没有奏效。我已经用这个替换了movement()
Player 类中函数的内容(作为参考,它被称为 every 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