global images?

BlitzMax Forums/BlitzMax Programming/global images?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

I use something like this but with wrappers around the images like Vilu. You should never call LoadImage more than you need to is I think the short answer.

Type TimageLibrary Extends Tmap
Method get:Timage(path:String)
	Local o:Object = MapValueForKey(Self, path)
	If TImage(o) Return TImage(o)
EndMethod
Method open(path:String, frames:Int = 1) 
	Local i:Timage
	If frames > 1
		Local temp:Timage = LoadImage(path) 
		Local w:Int = ImageWidth(temp) 
		Local h:Int = ImageHeight(temp) 
		i = LoadAnimImage(path, w / frames, h, 0, frames)
	Else
		i = LoadImage(path)
	EndIf
	MapInsert(Self, path, i)
EndMethod
Method list:TMapEnumerator() 
	Return MapKeys:TMapEnumerator( Self )
EndMethod
EndType