OpenFL:不同目标的编译结果不一致

时间:2014-02-24 03:35:36

标签: haxe openfl

我有以下简单的haxe / openfl代码,并且无法弄清楚为什么它应该为一个目标编译而对其他目标失败。我的理解是OpenFL应该将flash API引入所有支持的语言/平台。

//test.hx
import flash.display.Sprite;
class Test {
  static function main() {
      var g:Sprite = new Sprite();
      g.graphics.drawPath([1, 2], [1.1, 1.2,2.1,2.2]); //problem line
  }
}

编译neko目标时编译正常:

$ haxelib run openfl build project.xml neko

但是,将其编译为flash时会产生错误:

$ haxelib run openfl build project.xml flash
./Test.hx:5: characters 23-29 : Array<Int> should be flash.Vector<Int>
./Test.hx:5: characters 23-29 : For function argument 'commands'

对我来说这看起来很奇怪,因为从错误消息来看,对于一个目标,函数drawPath需要Array类型参数,对于另一个目标,同一函数需要Vector输入参数。

知道为什么会这样,以及如何让这两个目标都有效?

顺便说一句,如果我把它编译成HTML5,我得到了:

$ haxelib run openfl build project.xml html5
./Test.hx:5: characters 3-22 : flash.display.Graphics has no field drawPath

此功能甚至不存在。以上结果是截至2014年2月的Haxe 3.0.1和最新的openfl。

2 个答案:

答案 0 :(得分:1)

OpenFL需要openfl.Vector,如Graphics.drawPath方法签名中所示:

public function drawPath (commands:Vector<Int>, data:Vector<Float>, winding:GraphicsPathWinding = null):Void

当mac和neko目标接受数组时,Flash需要OpenFL向量类;另外,html5目标没有实现drawPath

因此,实现命令和数据参数如下:

package;

import openfl.Vector;
import openfl.display.Sprite;
import openfl.display.Graphics;

class Main extends Sprite {

    public function new() {
        super();

        var g:Graphics = graphics;
        g.lineStyle(2, 0x0);

        var commands:Vector<Int> = [1, 2, 2, 2, 2];
        var data:Vector<Float> = [20.0,10.0, 
                                  50.0,10.0,
                                  50.0,40.0, 
                                  20.0,40.0, 
                                  20.0,10.0];
        g.drawPath(commands, data);
    }

}

答案 1 :(得分:-1)

可能因为您正在执行命令而存在问题:

haxelib run openfl build project.xml flash

也许你还没有安装在LiME(Light Media Engine)上运行的最新OpenFL,或者你有一个旧版本的FlashDevelop,它使用较旧的OpenFL版本构建你的应用程序。

我手动从命令行执行所有构建,现在,新命令是:

lime build flash

是的,尽管我记得JS api没有drawPath方法,所以没有运气。然而,这可能会改变,但如果没有,我建议为HTML5编写一个编译条件并使用其他方法:绘制线条,曲线等。

请查看OpenFL官方网站了解更多信息 - 它编写得非常好: http://www.openfl.org/documentation/

请注意,OpenFL正在频繁更改,有时会让人感到困惑,因为构建命令和依赖包会发生很大变化。您必须始终检查OpenFL的当前状态。我很确定它会在半年左右再次发生变化。

相关问题