Page 1 of 3

How do I remove drawn images & printed text?

Posted: Fri Mar 13, 2015 6:07 pm
by RBXcpmoderator12345
Without removing the file? (for images only)
What I'm trying to do is when a certain position is clicked, it changes backgrounds.

Re: How do I remove drawn images & printed text?

Posted: Fri Mar 13, 2015 6:15 pm
by RBXcpmoderator12345
is it image = nil?

Re: How do I remove drawn images & printed text?

Posted: Fri Mar 13, 2015 6:58 pm
by s-ol
RBXcpmoderator12345 wrote:Without removing the file? (for images only)
What I'm trying to do is when a certain position is clicked, it changes backgrounds.
you stop drawing something by not drawing it anymore. That's all there is to it.

Re: How do I remove drawn images & printed text?

Posted: Fri Mar 13, 2015 8:34 pm
by davisdude
Something like this:

Code: Select all

-- in love.draw
if imageClicked then
    -- Draw one thing
else
    -- Draw another thing
end
Then have something in love.update that sets imageClicked to true on click.

Re: How do I remove drawn images & printed text?

Posted: Fri Mar 13, 2015 8:57 pm
by TheOddByte
davisdude wrote: Then have something in love.update that sets imageClicked to true on click.
Or he could use love.mousepressed :P
But as I see this it's easiest as suggested by davisdude, now if you have multiple images and want to change an image depending on where you clicked or something it's better to use a table where you contain all of them.

Code: Select all

local index  = 1
local images = {
    love.graphics.newImage( "foo.png" );
    love.graphics.newImage( "bar.png" );
}


function love.draw()
    love.graphics.draw( images[index], 1, 1 )
end

function love.mousepressed( x, y, button )
    // Some code here
end

Re: How do I remove drawn images & printed text?

Posted: Fri Mar 13, 2015 10:16 pm
by RBXcpmoderator12345
my updated code:

Code: Select all

function wait(time) --  so I do less typing and i feel familiar with it
love.timer.sleep(time)
end

function updateGameMode()
gameMode = "playing"
end

function love.load() -- LOAD ALL THE IMAGES AND SOUNDS
Master_Illumina = love.graphics.newImage("Master Illumina (illuminabreaks).png")
fanzo = love.graphics.newImage("fanzo (guestslovepizza).png")
narbthenoob = love.graphics.newImage("narbthenoob (luckyleo1231).png")
newbag = love.graphics.newImage("newbag (damanius).png")
wires = love.graphics.newImage("wires.exe (vengancevinny).png")
mask = love.graphics.newImage("mask (lolhatz).png")
wizgo = love.graphics.newImage("wizgo (creepywriter).png")
character = love.graphics.newImage("gfx/character.png")
ghost = love.graphics.newImage("ghost.mp4 (successfulfundude).png")
plush1 = love.graphics.newImage("plushie (blockopsmaster).png")
plush2 = love.graphics.newImage("plushie2(Robloxia38).png")
theme = love.audio.newSource("werenotalone(spookysoundtrack.com).mp3")
scream = love.audio.newSource("scaryscream(soundbible.com).mp3")
gameMode = "nothing yet"
kaito4life = love.graphics.newImage("Kaito4life(collestgirl).png")
end

backgrounds = {
love.graphics.newImage("background.png");
love.graphics.newImage("titlescreen.png");
}

function love.draw() 
love.graphics.draw(backgrounds[index], 1, 1)
end

function love.keypressed(key)
if key == "q" then
love.graphics.draw(backgrounds[2])
else
wait(10000000000000000000000000000000000000000000000000000000000000000)
print("Why are you waiting this long!!?!?!?!?")
end
end
Ignore the names of the images I'm trying to load, the characters are based on people from another site and they requested to be named that way

Re: How do I remove drawn images & printed text?

Posted: Fri Mar 13, 2015 11:11 pm
by RBXcpmoderator12345
bump

Re: How do I remove drawn images & printed text?

Posted: Fri Mar 13, 2015 11:40 pm
by arampl
You can't draw anything outside of love.draw()

Code can look like this:

Code: Select all

curr = 1

function love.draw()
love.graphics.draw(backgrounds[curr])
end

function love.keypressed(key)
if key == "q" then
curr = 2
else

Re: How do I remove drawn images & printed text?

Posted: Sat Mar 14, 2015 3:31 am
by RBXcpmoderator12345
can i have a function in a if statement in a function then?
like this:

Code: Select all

function love.keypressed(key) 
if key == "q" then
function love.draw()
love.graphics.draw(image)
end
end
end

Re: How do I remove drawn images & printed text?

Posted: Sat Mar 14, 2015 5:44 am
by arampl
Yes, you can. But why do you want to put love.draw() inside keyboard event?