Terminal 未找到Haxe类型
我正在尝试运行最基本的Haxe程序,但不断出现错误Terminal 未找到Haxe类型,terminal,haxe,haxeflixel,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 M
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));
}
}
包;
导入flash.display.Sprite;
导入flash.display.StageAlign;
导入flash.display.StageScaleMode;
导入flash.events.Event;
导入flash.Lib;
导入flixel.FlxGame;
导入flixel.FlxState;
类Main扩展了Sprite{
var gameWidth:Int=640;//游戏的宽度,以像素为单位(根据缩放的不同,实际像素可能会减少/增加)。
var gameHeight:Int=480;//游戏的高度以像素为单位(根据您的缩放,实际像素可能会减少/增加)。
var initialState:Class=MenuState;//游戏开始时的FlxState。
var zoom:Float=-1;//如果为-1,将自动计算缩放以适应窗口尺寸。
var framerate:Int=60;//游戏每秒应该运行多少帧。
var skipSplash:Bool=false;//是否跳过在发布模式下显示的flixel启动屏幕。
var startFullscreen:Bool=false;//是否在桌面目标上全屏启动游戏
//从现在起,你几乎可以忽略一切——你的代码应该在你的州中。
公共静态函数main():Void
{
Lib.current.addChild(newmain());
}
公共职能(新增)
{
超级();
如果(阶段!=null)
{
init();
}
其他的
{
addEventListener(Event.ADDED_TO_STAGE,init);
}
}
私有函数init(?E:事件):Void
{
if(hasEventListener(将Event.ADDED_添加到_阶段))
{
removeEventListener(Event.ADDED_TO_STAGE,init);
}
设置游戏();
}
私有函数setupGame():Void
{
var stageWidth:Int=Lib.current.stage.stageWidth;
var stageHeight:Int=Lib.current.stage.stageHeight;
如果(缩放==-1)
{
var ratioX:Float=舞台宽度/游戏宽度;
风险比率:浮动=舞台高度/游戏高度;
zoom=Math.min(ratioX,ratioY);
gameWidth=Math.ceil(stageWidth/zoom);
gameHeight=Math.ceil(stageHeight/zoom);
}
addChild(新FlxGame(游戏宽度、游戏高度、初始状态、缩放、帧速率、帧速率、skipSplash、startFullscreen));
}
}
只有通用模板文件。当我在终端(运行Mac OS X El Capitan)中运行它时,我得到以下错误:
Main.hx:8:角色7-21:未找到类型:flixel.FlxGame
在安装或其他方面并没有任何问题,而且我是Haxe的新手,所以我不知道从哪里开始。有什么想法吗
谢谢:)您在尝试运行游戏时是否添加了库 您可以使用命令行
haxe-lib-flixel-main…
来实现这一点
或者通过写入包含所有CLI参数的hxml文件:
-lib flixel
-main Main
在@Gama11评论之后更新:
HaxeFlixel使用OpenFL格式作为编译信息(请参阅)
因此,您应该在
Project.xml
文件中包含flixel库,使用:
。当然,您需要安装haxeflixel库flixel是在OpenFL之上构建的。OpenFL项目是使用lame
及其,而不是haxe
和hxml
编译的。噢@Gama11,我忘了这一点。你是对的。我会更新一下我的答案。你安装了HaxeFlixel吗?当您键入haxelib list
时,是否会看到类似于flixel:3.3.11
的内容?您使用什么命令来运行它?