xna - When to load textures? -
i'm working on couple of windows phone projects (although question may fit iphone/android) , got me thinking, when best time load textures content manager.
at first, loading them up, game base class, , passing them along required. getting sick of this, have created small resource manager class, pass out requires it.
so i'm thinking, perhaps best load texture in, when class requires it, , assign variable, when need again - ready go... best way (efficient?, fastest?) handle loading resources? if not, how recommend go it?
don't create kind of "resource manager" class. pass xna contentmanager
class around (the instance game.content
).
the default content manager automatically handle reusing loaded objects you. can content.load<texture2d>("something")
multiple places , same texture instance.
so if have bunch of classes game objects, standard design of giving each update
, draw
method call respective methods in game
- add method: loadcontent
classes, accepts argument of contentmanager
.
you can call method game's loadcontent
method.
if, later, want implement kind of system of delay-loading things (for example: loading content when changing levels), can call game classes' loadcontent
method game's update
method (but keep in mind loading content slow - might want throw "loading" screen).
unloading content trickier. create must unload. loaded contentmanager
(because instances shared) should unloaded content manager (game
handle unloading content
member when needs to). may find this blog post worth reading.
Comments
Post a Comment