HaxeFlixel - 错误:无效操作(%),可能与loadGraphic有误

时间:2015-11-27 05:36:09

标签: haxe haxeflixel

我搜索了HaxeFlixel论坛,google,在这里设法修复了一些其他问题,同时尝试自己调试,但是问题本身没有运气。

最好的我可以说,在使用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;
        }

    }

}

0 个答案:

没有答案