0

我在这里搜索了 HaxeFlixel 论坛,谷歌,并在尝试自己调试时设法解决了一些其他问题,但问题本身没有运气。

尽我所能说,我在使用时似乎做了一些愚蠢的事情loadGraphic()?我一直想知道我是否打错了,精灵的 png 不存在,这就是它的原因null,但我已经检查了足够多的时间,认为可能不是。

当我搬到PlayState...时,这是我在 neko 中的错误。

haxelib run lime run "Project.xml" neko -debug
Running process: C:\HaxeToolkit\haxe\haxelib.exe run lime run "Project.xml" neko -debug
Invalid operation (%)
Called from flixel.animation.FlxAnimationController::set_frameIndex line 638
Called from flixel.FlxSprite::updateFrameData line 1197
Called from flixel.FlxSprite::loadGraphic line 347
Called from Josh::new line 26
Called from Josh::$init line 13
Called from PlayState::addJosh line 54
Called from PlayState::create line 37
Called from flixel.FlxGame::switchState line 583
Called from flixel.FlxGame::update line 668
Called from flixel.FlxGame::step line 648
Called from flixel.FlxGame::onEnterFrame line 493
Called from openfl._legacy.events.EventDispatcher::dispatchEvent line 98
Called from openfl._legacy.display.DisplayObject::__dispatchEvent line 182
Called from openfl._legacy.display.DisplayObject::__broadcast line 161
Called from openfl._legacy.display.DisplayObjectContainer::__broadcast line 286
Called from openfl._legacy.display.Stage::__render line 1103
Called from openfl._legacy.display.Stage::__checkRender line 351
Called from openfl._legacy.display.Stage::__pollTimers line 1084
Called from openfl._legacy.display.Stage::__doProcessStageEvent line 430
Done(1)

这是我切换到闪光灯时的错误PlayState...

TypeError: Error #2007: Parameter sourceBitmapData must be non-null.
    at flash.display::BitmapData/copyPixels()
    at flixel::FlxSprite/draw()[C:\HaxeToolkit\haxe\flixel\3,3,11\flixel\FlxSprite.hx:777]
    at flixel.group::FlxTypedGroup/draw()[C:\HaxeToolkit\haxe\flixel\3,3,11\flixel\group\FlxTypedGroup.hx:108]
    at flixel::FlxState/draw()[C:\HaxeToolkit\haxe\flixel\3,3,11\flixel\FlxState.hx:58]
    at flixel::FlxGame/draw()[C:\HaxeToolkit\haxe\flixel\3,3,11\flixel\FlxGame.hx:805]
    at flixel::FlxGame/onEnterFrame()[C:\HaxeToolkit\haxe\flixel\3,3,11\flixel\FlxGame.hx:506]

PlayState.hx

package;

import flixel.FlxCamera;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.FlxObject;
import flixel.util.FlxPoint;
import flixel.text.FlxText;
import flixel.tile.FlxTilemap;
import flixel.ui.FlxButton;
import flixel.util.FlxMath;
import flixel.util.FlxTimer;
import openfl.Assets;

/**
 * A FlxState which can be used for the actual gameplay.
 */
class PlayState extends FlxState
{
    private var level:FlxTilemap;
    private var camera:FlxCamera;
    public var josh:Josh;


    /**
     * Function that is called up when to state is created to set it up. 
     */
    override public function create():Void
    {
        super.create();

        addLevel();
        addJosh(12, 125);

        camera = FlxG.camera;
        FlxG.camera.follow(josh, FlxCamera.STYLE_LOCKON);
        add(camera);
    }

    function addLevel():Void
    {
        level = new FlxTilemap();
        level.loadMap(Assets.getText("assets/data/map.csv"), "assets/images/tileset.png", 32, 32);
        level.setTileProperties(1, FlxObject.NONE);
        add(level);
    }

    function addJosh(X:Int, Y:Int):Void
    {
        josh = new Josh(X, Y);
        add(josh);
    }

    /**
     * Function that is called when this state is destroyed - you might want to 
     * consider setting all objects this state uses to null to help garbage collection.
     */
    override public function destroy():Void
    {
        super.destroy();
    }

    /**
     * Function that is called once every frame.
     */
    override public function update():Void
    {
        super.update();

        FlxG.collide(level, josh);
    }

}

Josh.hx

package;

import flixel.FlxSprite;
import flixel.FlxG;
import flixel.FlxObject;
import flixel.util.FlxMath;
import flixel.util.FlxTimer;

/**
 * ...
 * @author Jacob
 */
class Josh extends FlxSprite
{

    var maxSpeed:Int = 120;
    var gravity:Int = 100;
    var maxFallSpeed:Int = 300;
    var jumpForce:Int = 140;
    var maxAcceleration:Int = 300;
    var _drag:Float = 1000;

    public function new(X:Float, Y:Float) 
    {
        super(X * 32, Y * 32 - 32);
        loadGraphic("assets/images/Mugger Space Cadet.png", true, 32, 64);
        setSize(25, 59);
        offset.set(4, 5);

        maxVelocity.y = maxFallSpeed;
        acceleration.y = gravity;
        drag.x = _drag;
    }

    override public function update():Void
    {
        if (alive) controls();

        super.update();
    }

    function controls():Void
    {
        var xForce:Float = 0;
        var jumping:Bool = false;

        if (FlxG.keys.anyPressed(["LEFT", "A"])) xForce--;
        if (FlxG.keys.anyPressed(["RIGHT", "D"])) xForce++;
        if (FlxG.keys.anyJustPressed(["SPACE", "UP", "W"])) jumping = true;
        if (FlxG.keys.anyJustReleased(["SPACE", "UP", "W"])) velocity.y = velocity.y * 0.5;

        xForce = FlxMath.bound(xForce, -1, 1);
        acceleration.x = xForce * maxAcceleration;
        if (jumping && isTouching(FlxObject.FLOOR)) {
            var finalJumpForce:Float = -(jumpForce + Math.abs(velocity.x * 0.25));
            velocity.y = finalJumpForce;
        }

    }

}
4

0 回答 0