LoadImage from different locations

Monkey Forums/Monkey Programming/LoadImage from different locations

Raz(Posted 2011) [#1]
I'm wondering...
Class Animal
Field Image1:Image
Field Image2:Image
Method New()
Image1 = LoadImage("dog.png")
Image2 = LoadImage("dog.png")
End
End

If dog.png has already been loaded, does the second loadimage call load it into memory at a different location, or simply refer to the existing instance in memory?

Thanks
-Chris


Shinkiro1(Posted 2011) [#2]
It will load it into a different memory area.

You can design your own image loading function that checks if an image is already loaded. I've posted code how to do this somewhere on the boards here (sorry, don't know where).
Basically you use a Map<path:String,image:Image>.


Raz(Posted 2011) [#3]
Thanks Shinkiro, that's a good idea. I use the same image for lots of different things and that seems the easiest way of dealing with it :)


therevills(Posted 2011) [#4]
Or you can just do this:

Class Animal
	Field Image1:Image
	Field Image2:Image

	Method New()
		Image1 = LoadImage("dog.png")
		Image2 = Image1
	End
End



Raz(Posted 2011) [#5]
Hi therevills, the above was just a very simple example. I'm actually loading the same image across a few different classes so I don't want one class to rely on another.


therevills(Posted 2011) [#6]
Ah... in that case you need a resource manager of some kind like what Shinkiro1 has suggested, we've got something similar in Diddy - either that or heaps of globals ;)