找不到Haxe类型

时间:2015-12-23 11:14:32

标签: terminal haxe haxeflixel

我正在尝试运行最基本的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的新手,所以我不知道从哪里开始。有什么想法吗?

谢谢:)

1 个答案:

答案 0 :(得分:1)

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

您可以使用命令行var angles = transform.localEulerAngles; transform.localEulerAngles = new Vector3(0, angles.y, 0); 来完成此操作。

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

haxe -lib flixel -main Main ...

@ Gama11评论后更新:

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

因此,您应该在-lib flixel -main Main 文件中使用<haxelib name="flixel" />添加包含flixel库。