On the wiki, it said this; Shape:destroy()
but when I make a image, I do this:
image = love.graphics.newImage("block")
love.graphics.draw(block,400,300)
Now how would I remove it?
Thanks for your help in my first language guys, it is appreciated
removing images
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- HugoBDesigner
- Party member
- Posts: 403
- Joined: Mon Feb 24, 2014 6:54 pm
- Location: Above the Pocket Dimension
- Contact:
Re: removing images
You'll have to use an external variable. You can't "unload" images while using love.graphics, but you can do this:Findo777 wrote:On the wiki, it said this; Shape:destroy()
but when I make a image, I do this:
image = love.graphics.newImage("block")
love.graphics.draw(block,400,300)
Now how would I remove it?
Thanks for your help in my first language guys, it is appreciated
Code: Select all
[on love_load]
image = love.graphics.newImage("block")
[wherever you'll remove the image]
image = false
[on love_draw]
if image then
love.graphics.draw(image,400,300)
end
Code: Select all
[on love_load]
image = love.graphics.newImage("block")
drawimage = true
[wherever you'll remove the image]
drawimage = false
[wherever you'll re-add the image]
drawimage = true
[on love_draw]
if drawimage then
love.graphics.draw(image,400,300)
end
Re: removing images
Sorry... this is not working for me....
Re: removing images
For a small game there's not really any need to 'remove' images. Just don't draw them.
But if you really need to, I think something like this would completely remove an image from the memory
But if you really need to, I think something like this would completely remove an image from the memory
Code: Select all
image = love.graphics.newImage("whatever.jpg")
image = nil
collectgarbage()
Re: removing images
What if the images are stored in a table, how can i clear the table and free the memory?
- HugoBDesigner
- Party member
- Posts: 403
- Joined: Mon Feb 24, 2014 6:54 pm
- Location: Above the Pocket Dimension
- Contact:
Re: removing images
If the table consists ONLY of images you wanna remove, I think you can pretty much do this:kingomar wrote:What if the images are stored in a table, how can i clear the table and free the memory?
Code: Select all
imageTable = {}
Code: Select all
imageTable = {x = 10, y = 20, image = image, rotation = 0} --just an example. The image is "imageTable.image"
imageTable.image = nil --or imageTable["image"]
Re: removing images
I think that you are just misunderstanding things. You do not need to remove images, memory is being handled by the garbage collection and you need A LOT of images before this even makes a small difference.
An example:
This will make it so that the player is visible when he is alive, and the second he is no longer alive, he is not visible.
And when it comes to images the vast majority will be reused later on in a game, so in MOST cases it is actually a very bad idea to try to "unload" an image.
That has to do with the box2d module (Physics) and has nothing to do with images.Findo777 wrote:On the wiki, it said this; Shape:destroy()
An image is drawn every frame, if you stop calling "love.graphics.draw(block,400,300)" the image will no longer be visible.Findo777 wrote: image = love.graphics.newImage("block")
love.graphics.draw(block,400,300)
Now how would I remove it?
An example:
Code: Select all
If player.alive == true then
love.graphics.draw(player.img,player.x,player.y)
end
And when it comes to images the vast majority will be reused later on in a game, so in MOST cases it is actually a very bad idea to try to "unload" an image.
- pixelprato
- Prole
- Posts: 2
- Joined: Wed Sep 15, 2021 10:18 am
- Contact:
Re: removing images
Thx guys !!!
settings up my unused images to nil and collectgarbage() works perfectly
settings up my unused images to nil and collectgarbage() works perfectly
Re: removing images
This is an old thread (2014). Things have changed since; now there is image:release() that you can use to free an image.
Re: removing images
Note that after calling any :release() function, it's also best to set that variable to nil.
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
Who is online
Users browsing this forum: Ahrefs [Bot] and 6 guests