Ebiten: Preferred way to handle/bundle static assets?

Created on 17 May 2020  路  2Comments  路  Source: hajimehoshi/ebiten

I just completed my first Ebiten game (https://github.com/mortenson/trianglovers), which uses https://github.com/gobuffalo/packr to bundle static assets into the windows/mac/linux binaries.

I noticed that packr doesn't support js/wasm, so my game couldn't be built for the browser. I'm wondering if there's a preferred way to handle static assets in a way that works for all build targets (including JS and mobile). If it's better not to bundle at all and have assets as normal files that's OK with me, it'd just be good to know for the future! Thanks for the support.

question

All 2 comments

Hi,

I don't have a strong recommendation. I always use my own tool file2byteslice. This is simple and just generates a byte slice from a file. This should work anywhere :-)

As this tool is so simple, I know some people complain about lack of features. You can find more rich tools at Awesome Go.

That's perfect! Thank you.

I wrote some bash to test this out and see about automating something similar to packr,:

find assets/ -type f -exec bash -c 'echo file2byteslice -input "$1" -output $(echo "$1" | sed 's/assets/bytes/' ).go -var asset_$(basename "$1" | sed -e "s/\..*//" -e "s/-/_/")' _ {} \;
file2byteslice -input assets/eyeball.png -output bytes/eyeball.png.go -var asset_eyeball
file2byteslice -input assets/Archivo-SemiBold.ttf -output bytes/Archivo-SemiBold.ttf.go -var asset_Archivo_SemiBold
file2byteslice -input assets/Jost-Medium.ttf -output bytes/Jost-Medium.ttf.go -var asset_Jost_Medium
file2byteslice -input assets/LobsterTwo-Italic.ttf -output bytes/LobsterTwo-Italic.ttf.go -var asset_LobsterTwo_Italic
file2byteslice -input assets/arrow.png -output bytes/arrow.png.go -var asset_arrow
file2byteslice -input assets/dragcursor.png -output bytes/dragcursor.png.go -var asset_dragcursor
file2byteslice -input assets/background.png -output bytes/background.png.go -var asset_background
file2byteslice -input assets/mouth.png -output bytes/mouth.png.go -var asset_mouth
file2byteslice -input assets/bgm.mp3 -output bytes/bgm.mp3.go -var asset_bgm
file2byteslice -input assets/eyeinner.png -output bytes/eyeinner.png.go -var asset_eyeinner

Basically for every file in assets, output a file2byteslice file in bytes, with a go-safe variable name. I'll close this out and use this on my next game for sure.

Was this page helpful?
0 / 5 - 0 ratings