Page 1 of 1

How to remove an image?

Posted: Sun Aug 09, 2015 6:39 am
by nerfman7
So I need to remove an image and a song using an if statement. If gamestate = play then (Remove image,song)

Code: Select all

    gamestate = "title"

    function love.update(dt)
		   mainmenu = love.graphics.newImage("back.jpg")
		   playbackground = love.graphics.newImage("playbackground.png")
music = love.audio.newSource( 'background.mp3', 'stream' )
music:setLooping( true ) --so it doesnt stop
music:play()
      if gamestate == "title" then
        if love.keyboard.isDown("return", "enter") then
          gamestate = "play"
        end
      else
        -- do your game logic here
	  end
      end
    end

    function love.draw()
	love.graphics.draw(mainmenu)
      if gamestate == "title" then
        love.graphics.print( "Press Enter To Play")
      else
        -- draw your game here
      end
    end
    end

Please Help :)

Re: How to remove an image?

Posted: Sun Aug 09, 2015 8:01 am
by arampl

Re: How to remove an image?

Posted: Sun Aug 09, 2015 8:08 am
by zorg
First, please check out the wiki if you haven't yet, since it will tell you, if you look up all those love._.new_ functions, that you should not use them in love.update, since it will run every frame.

Use love.load to load assets only once at the beginning of the game;
and also use the local keyword to not pollute the global namespace with variables.