How do I remove drawn images & printed text?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
RBXcpmoderator12345
Citizen
Posts: 59
Joined: Sat Mar 07, 2015 11:53 pm

How do I remove drawn images & printed text?

Post 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.
RBXcpmoderator12345
Citizen
Posts: 59
Joined: Sat Mar 07, 2015 11:53 pm

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

Post by RBXcpmoderator12345 »

is it image = nil?
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

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

Post 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.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

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

Post 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.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
User avatar
TheOddByte
Prole
Posts: 35
Joined: Sun Dec 15, 2013 7:15 pm

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

Post 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
What's the object-oriented way to get wealthy? Inheritance.
RBXcpmoderator12345
Citizen
Posts: 59
Joined: Sat Mar 07, 2015 11:53 pm

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

Post 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
RBXcpmoderator12345
Citizen
Posts: 59
Joined: Sat Mar 07, 2015 11:53 pm

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

Post by RBXcpmoderator12345 »

bump
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

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

Post 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
RBXcpmoderator12345
Citizen
Posts: 59
Joined: Sat Mar 07, 2015 11:53 pm

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

Post 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
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

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

Post by arampl »

Yes, you can. But why do you want to put love.draw() inside keyboard event?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest