A module for managing resources needed for games. This currently only manages textures, but a future version might add sounds, 3d-meshes etc..
Suggested import:
import Game.Resources as Resources exposing (Resources)Add resources to your initialModel:
initialModel =
{ ..
, resources = Resources.init
}Add the resources message to your Msg
type Msg
= ..
| Resources Resources.MsgLoad textures at init:
init =
initialModel
! [ Resources.loadTextures [ "images/box.png" ]
|> Cmd.map Resources
]Add a case for the Resources.Msg in update
Resources msg ->
{ model | resources = Resources.update msg model.resources } ! []Request your texture when you need it
Resources.getTexture "images/box.png" resourcesLoads a list of textures from the given urls. PNGs and JPEGs are known to work. For WebGL make sure that your textures have a dimension with a power of two, e.g. 2^n x 2^m
Returns a maybe as the texture might not be loaded yet.
Same as loadTextures, but gives you more control by being able to react to a texture loading error and by specifying a texture filter.
loadTexturesWithConfig
{ success = Resources
, failed = LoadingTextureFailed
}
[ (linear, "images/blob.png"), (nearest, "images/box.jpeg") ]These are just an alias for the same functions in the WebGL library
The main type of this library