Can’t access GIF with Assets.getText

Hello,

I have a very similar issue to this post Can't access GIF with Assets.getBytes but the fix proposed does not work for me… :frowning:
Basically, I want to display an animated gif using the haxe-gif library:

var bytes = haxe.io.Bytes.ofString(Assets.getText("images/mygif.gif"));
addChild(new AnimatedGif(bytes).play());

But I got the following error:

There is no String Asset with an id of images/mygif.gif

Same error (no ByteArray asset) if I do:

var bytes = haxe.io.Bytes.ofData(Assets.getBytes("images/mygif.gif"));
addChild(new AnimatedGif(bytes).play());

So I added the type “binary” to my assets tag in the project.xml file as suggested in the post mentioned above but I still got the same error.

<assets type="binary|images|text" path="../../Assets/img/hd" rename="images"/>

Any idea?
Thanks!

I don’t think you can have multiple type for an assets tag,
they are used to override the type inferred by the tool not choose what gets added.

Instead do something like this:
<assets type="binary" path="../../Assets/img/hd" rename="images" include="*.gif" />

Hi,

Thank you, following your advice I can now load the gif. But the animation won’t play :(. I tried with 2 libraries, haxe-gif and yagp

Haxe-gif:

var bytes = haxe.io.Bytes.ofData(Assets.getBytes("images/mygif.gif"));
addChild(new AnimatedGif(bytes).play());

yagp:

var gif:Gif = GifDecoder.parseByteArray(Assets.getBytes("binaries/" + src));
var player:GifPlayer = new GifPlayer(gif);
var wrapper:GifPlayerWrapper = new GifPlayerWrapper(player);
addChild(wrapper);

I got the same result for both: only the first frame is displayed and the animation does not run. I only target Flash and my gif size is 960x540 pixel.

I tried with different files and the animation is correctly played in a browser so the issue does not come from there… I join a very basic example.

我也遇到了同样的问题,有一个完整的demo就好了

这个bug已经解决了,需要的朋友可以参考下,已经推送上去了,但暂时没有合并 。https://github.com/SempaiGames/haxe-gif/pulls

1 Like