Reputation: 2210
I am trying to make a flappy bird game in Haskell and I'd like to know if there's a way to "compile" the .bmp files into the binary? So I can only share the executable and don't need a folder with the sprites.
I am using gloss-1.13.0.1
and loading the bmp as
bg0Pic = unsafePerformIO . loadBMP $ "bg0.bmp"
I know unsafePerformIO
is not good practice but that's not of my concern yet. Should I use a different approach so that the compiler knows I need that image or is there just no way to do that?
Can find the whole code on GitHub
Upvotes: 4
Views: 175
Reputation: 31315
You can use the file-embed package, which uses Template Haskell to embed files.
https://www.stackage.org/package/file-embed
For example:
sprites :: ByteString
sprites = $(embedFile "images/sprites.png")
wordsPic :: Picture
wordsPic = fromMaybe mempty
(either (\_ -> Nothing) Just (decodeImage sprites)
>>= fromDynamicImage)
Upvotes: 4
Reputation: 3589
One approach is to use Data Files with cabal.
The idea is that you add all data files (text, images, sprites, other binaries) you want to bundle with your application and access at runtime under the Data-Files
header in your .cabal file.
This will cause cabal to generate a Paths module for you, which you can access in whatever module needs it.
More info can be found here!
Upvotes: 2