How do you delete a picture that you have drawn?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
nPwn
Prole
Posts: 4
Joined: Thu Jan 26, 2012 12:59 am

How do you delete a picture that you have drawn?

Post by nPwn »

Like I have this:

function love.draw()
love.graphics.draw(one,0, 0)

end

how would I erase the picture "one"?
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: How do you delete a picture that you have drawn?

Post by Jasoco »

Simple answer. Stop drawing it. That's basically it. Use if's and then's and variables to determine if it's supposed to draw or not.
nPwn
Prole
Posts: 4
Joined: Thu Jan 26, 2012 12:59 am

Re: How do you delete a picture that you have drawn?

Post by nPwn »

Jasoco wrote:Simple answer. Stop drawing it. That's basically it. Use if's and then's and variables to determine if it's supposed to draw or not.
But if I have already drawn it then how would I stop? This is what I have.

local one, two, three

local a = 1

function love.load()
one = love.graphics.newImage("one.png")
two = love.graphics.newImage("two.png")
three = love.graphics.newImage("three.png")
love.graphics.setBackgroundColor(255,255,255)
end

timer, called = 0, 0
function love.update(dt)
if a == 4 then
return end
timer = timer + dt
if timer > 1 and called < 2 then
if a == 1 then
function love.draw()
love.graphics.draw(three,0, 0)
a = 2
end
elseif a == 2 then
function love.draw()
love.graphics.draw(two,0, 0)
a = 3
end
elseif a == 3 then
function love.draw()
love.graphics.draw(one,0, 0)
a = 4
end
end
timer = 0
called = called + 1
end
end
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: How do you delete a picture that you have drawn?

Post by Jasoco »

Please edit your post to use the CODE tags. I can't read that code without indentation.
nPwn
Prole
Posts: 4
Joined: Thu Jan 26, 2012 12:59 am

Re: How do you delete a picture that you have drawn?

Post by nPwn »

How do I do that?
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: How do you delete a picture that you have drawn?

Post by tentus »

When you paste code into your message, pit the button labeled "Code" just before you do so. It'll make it look like this:

Code: Select all

local one, two, three

local a = 1

function love.load()
   one = love.graphics.newImage("one.png")
   two = love.graphics.newImage("two.png")
   three = love.graphics.newImage("three.png")
   love.graphics.setBackgroundColor(255,255,255)
end

timer, called = 0, 0
function love.update(dt)
if a == 4 then 
return end
    timer = timer + dt
    if timer > 1 and called < 2 then
	if a == 1 then
       function love.draw()
    love.graphics.draw(three,0, 0)
	a = 2
end
elseif a == 2 then
 function love.draw()
    love.graphics.draw(two,0, 0)
	a = 3
end
elseif a == 3 then
 function love.draw()
    love.graphics.draw(one,0, 0)
	a = 4
end
end
        timer = 0
        called = called + 1
    end
end
Now, a quick correction that HAS TO be addressed immediately. function love.draw() should never be inside another function. Ever. Put functions and if statements inside of love.draw all you want, but not the other way around.

If you do that, your code comes out like this:

Code: Select all

function love.draw()
	if a == 1 then
		love.graphics.draw(one,0, 0)
	elseif a == 2 then
		love.graphics.draw(two,0, 0)
	elseif a == 3 then
		love.graphics.draw(three,0, 0)
	end
end
Or, even better, if you put your images into a table you can skip the if statement in love.draw, like this:

Code: Select all

function love.load()
   imgs = {}
   imgs[1] = love.graphics.newImage("one.png")
   imgs[2]= love.graphics.newImage("two.png")
   imgs[3] = love.graphics.newImage("three.png")
   love.graphics.setBackgroundColor(255,255,255)
end

function love.draw()
	love.graphics.draw(imgs[a],0, 0)
end
Kurosuke needs beta testers
nPwn
Prole
Posts: 4
Joined: Thu Jan 26, 2012 12:59 am

Re: How do you delete a picture that you have drawn?

Post by nPwn »

Okay thanks. I am new to love but not new to lua. I learned lua from ROBLOX originally. So back to my original question, is there anyway to "undraw" or erase an image?
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: How do you delete a picture that you have drawn?

Post by tentus »

As Jasoco started to explain, the answer is no, but it's an inappropriate question for Love. Once you've drawn an image, it will stay drawn for the rest of the frame. The very next frame starts you over though, the screen is clear out. Remember, love.draw is called each frame, so if you've got an FPS of 60, love.draw is being called 60 times in sequence.

This article will help you out a lot, conceptually.

tl;dr: Don't worry about it.
Kurosuke needs beta testers
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests