1

我正在尝试运行最基本的 Haxe 程序,但不断出现错误。

Main.hx文件如下所示:

package;

import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.Lib;
import flixel.FlxGame;
import flixel.FlxState;

class Main extends Sprite {

var gameWidth:Int = 640; // Width of the game in pixels (might be less / more in actual pixels depending on your zoom).
var gameHeight:Int = 480; // Height of the game in pixels (might be less / more in actual pixels depending on your zoom).
var initialState:Class<FlxState> = MenuState; // The FlxState the game starts with.
var zoom:Float = -1; // If -1, zoom is automatically calculated to fit the window dimensions.
var framerate:Int = 60; // How many frames per second the game should run at.
var skipSplash:Bool = false; // Whether to skip the flixel splash screen that appears in release mode.
var startFullscreen:Bool = false; // Whether to start the game in fullscreen on desktop targets

// You can pretty much ignore everything from here on - your code should go in your states.

public static function main():Void
{   
    Lib.current.addChild(new Main());
}

public function new() 
{
    super();

    if (stage != null) 
    {
        init();
    }
    else 
    {
        addEventListener(Event.ADDED_TO_STAGE, init);
    }
}

private function init(?E:Event):Void 
{
    if (hasEventListener(Event.ADDED_TO_STAGE))
    {
        removeEventListener(Event.ADDED_TO_STAGE, init);
    }

    setupGame();
}

private function setupGame():Void
{
    var stageWidth:Int = Lib.current.stage.stageWidth;
    var stageHeight:Int = Lib.current.stage.stageHeight;

    if (zoom == -1)
    {
        var ratioX:Float = stageWidth / gameWidth;
        var ratioY:Float = stageHeight / gameHeight;
        zoom = Math.min(ratioX, ratioY);
        gameWidth = Math.ceil(stageWidth / zoom);
        gameHeight = Math.ceil(stageHeight / zoom);
    }

    addChild(new FlxGame(gameWidth, gameHeight, initialState, zoom, framerate, framerate, skipSplash, startFullscreen));
}
}

只是通用模板文件。当我在终端(运行 Mac OS X El Capitan)中运行它时,我收到此错误:

Main.hx:8: characters 7-21 : Type not found : flixel.FlxGame

安装或任何东西都没有问题,而且我是 Haxe 的新手,所以我不知道从哪里开始。有任何想法吗?

谢谢 :)

4

1 回答 1

1

尝试运行游戏时是否添加了库?

您可以通过使用命令行来做到这一点haxe -lib flixel -main Main ...

或者通过编写一个包含所有 CLI 参数的 hxml 文件:

-lib flixel
-main Main

@Gama11 评论后更新:

HaxeFlixel 使用 OpenFL 格式作为编译信息(参见http://www.openfl.org/documentation/projects/project-files/xml-format/)。

<haxelib name="flixel" />因此,您应该在Project.xml文件中包含使用 : 的包含 flixel 库。

于 2015-12-23T12:16:58.200 回答