Should images be loaded in types?

BlitzMax Forums/BlitzMax Programming/Should images be loaded in types?

QuickSilva(Posted 2008) [#1]
I have seen a number of tutorials, like the create Asteroids in an hour one, that says that you can move your image loading routines into your types to make it truly modular. Example,

Type TShip
Field Image:TImage=LoadImage("SpaceShip.png")
End Type

I always thought that it was consider bad practice to load images after you have entered your main game loop. Is this a good idea or should you keep your image loading separate? Are things different in BMax?

Thanks for any advice.
Jason.


Grisu(Posted 2008) [#2]
I would use static arrays / variables to store my images in.
Loading images in the main loop / while creating types is never a good thing.


Brucey(Posted 2008) [#3]
Yeah, you never know how long it will take to load an image... which means your app could block for some time - per image. Of course, you can always use menus/between-level screens to do all that before jumping into a main game loop.

As you realise, you only want critical stuff going on in your main loop.


QuickSilva(Posted 2008) [#4]
Cheers, that`s what I thought.

Jason.


Who was John Galt?(Posted 2008) [#5]
If you declared image as a type global, it should load the image once at startup (I recommend trying it first, I'm not 100% sure). You could declare a bunch of global ship images, then just assign the image you choose to each ship as it's created.


QuickSilva(Posted 2008) [#6]
Interesting. Can anyone else confirm this? It is certainly neater to include your images within the type with a simple,

Type TShip
Global SpaceShip:TImage=LoadImage("SpaceShip.png")
End Type

Strangely, setting AutoImageFlags 0 doesn`t seem to work (i.e. images look blurry when scaled instead of being sharp) when my images are loaded from within my type like above. This command works fine when they are outside of the type. Is there a reason for this?

Jason.


Grisu(Posted 2008) [#7]
Just use some kind of shiptype flag. As John described....

This way is fast and you don't waste resources.


boomboom(Posted 2008) [#8]
you can store images in types just fine.

Type TShip
Field Image:TImage
End Type

Just then load them in afterwards, don't do it in your declaration


dmaz(Posted 2008) [#9]
I too keep my images in the type but I load them when I want. my most basic version is something like this...
[file] Main.bmx or LoadMedia.bmx
TAlien.img = LoadImage(...)

[file] TAlien.bmx
type TAlien
	global img:TImage
	
end type