Hi,
I just have a quick question. When one creates an image in love like this:
var = love.graphics.newImage( "smiley.png" )
var2 = love.graphics.newImage( "smiley.png" )
Will both variables share the same memory or are both independent from each other? I'm assuming the lower level image loader will know when to share memory with the same filename, but I'm not sure. I could try it out real quick...but I figure I ask here too for confirmation.
The same goes for other resources such as sound.
It's not a problem to build a resource management to handle the shared memory. Would be awesome to have some of those resource management handled at low level to a certain degree though...
Thanks.
resource sharing
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: resource sharing
I could be wrong, but I think it loads the image twice into two separate chunks of memory. That way, you can manipulate each instance of it separately. I know I ended up doing this in a project I worked on in löve, and it seemed to work alright that way, whereas when I pointed both variables to the same love.graphics.newImage(), I couldn't manipulate them separately.
Then again I could be completely wrong Paging rude to this thread!
Then again I could be completely wrong Paging rude to this thread!
Re: resource sharing
@Igmon: it will not share memory between them. This is by design. You should not need to create two Image objects from the same image.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: resource sharing
I think anjo is right. If you look at it from the LÖVE-perspective, caching images doesn't make much sense. If you really want that behavior, you could insert this (untested) code in your main.lua:
(note: it will probably fail hard anyway)
Code: Select all
local oldNewImage = love.graphics.newImage
local imageCache = {}
function love.graphics.newImage(name)
if not imageCache[name] then
imageCache[name] = oldNewImage(name)
end
return imageCache[name]
end
Help us help you: attach a .love.
Who is online
Users browsing this forum: Bing [Bot] and 5 guests