部署到Windows时嵌入和读取图像资产 [英] Embeding and reading image assets when deploying to Windows

查看:78
本文介绍了部署到Windows时嵌入和读取图像资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在其他平台上,我只能使用[Embed(source ="logo.gif")]或@:bitmap之类的东西,但是Windows/其他Cpp平台似乎没有其他选择.

In other platforms i could just use something like [Embed(source="logo.gif")] or @:bitmap, but it seems there is no option for that for Windows/Other Cpp platforms.

我尝试使用 EmbedAssets lib,但是它已经过时了.

I tried to use the EmbedAssets lib but it's outdated.

我也尝试使用nmml文件资源标签.这样我就可以将图像获取为haxe.sys.io.Bytes,但是要使用它,我需要将haxe.sys.io.Bytes转换为nme.utils.ByteArray.我还没有找到一种方法.

I also tried using the nmml file resource tag. With this i could get the image as haxe.sys.io.Bytes, but to use i need to convert haxe.sys.io.Bytes to nme.utils.ByteArray. I have not found a way to do this.

那么,在部署到Windows时如何在haxe/nme项目中嵌入图像?

So, what can i do to embed images on a haxe/nme project when deploying to Windows?

推荐答案

除了openfl.Assets,OpenFL还支持@:bitmap@:sound@:font@:file嵌入标签.

In addition to openfl.Assets, OpenFL supports @:bitmap, @:sound, @:font and @:file embed tags.

前者在您的项目XML文件中要求<assets path="to/assets" />,并且在Windows上,将文件与可执行文件一起复制.

The former requires <assets path="to/assets" /> in your project XML file, and on Windows, will copy the files alongside your executable.

embed标签要求您的资产文件基于其嵌入方式而位于源路径中,因此请在项目文件中使用<source path="to/assets" />.

The embed tags require that your asset files are in your source path based on the way they are embedded, so use <source path="to/assets" /> in the project file.

以下是使用@:bitmap标签的示例:

Here is an example that uses the @:bitmap tag:

package;


import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;

@:bitmap("nme.png") class Image extends BitmapData {}


class Main extends Sprite {


    public function new () {

        super ();

        var bitmap = new Bitmap (new Image (0, 0));
        addChild (bitmap);

        bitmap.x = (stage.stageWidth - bitmap.width) / 2;
        bitmap.y = (stage.stageHeight - bitmap.height) / 2;

    }


}

使用嵌入标签,资产将位于可执行文件中.

Using embed tags, the asset will be inside your executable.

这篇关于部署到Windows时嵌入和读取图像资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆