1

我有以下简单的 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

该功能甚至在这里都不存在。上面的结果是使用 Haxe 3.0.1 和截至 2014 年 2 月的最新 openfl。

4

2 回答 2

1

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

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

mac 和 neko 目标接受数组,而 Flash 需要 OpenFL 矢量类;此外,drawPath没有为 html5 目标实现。

因此,执行命令和数据参数如下:

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);
    }

}
于 2014-12-13T05:45:58.767 回答
-1

可能是您的问题存在,因为您正在执行命令:

haxelib run openfl build project.xml flash

也许您尚未安装在 LiME(光媒体引擎)上运行的最新 OpenFL,或者您拥有使用旧版 OpenFL 构建应用程序的旧版 FlashDevelop。

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

lime build flash

是的,据我所知,JS api 没有 drawPath 方法,所以那里没有运气。然而,现在这可能会改变,但如果没有,我建议为 HTML5 制作编译条件并使用其他方法:绘制直线、曲线等。

查看 OpenFL 官方网站了解更多信息——它写得很好: http ://www.openfl.org/documentation/

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

于 2014-02-25T01:20:53.573 回答