Few newbie questions

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
someguy99
Prole
Posts: 16
Joined: Tue Mar 17, 2009 5:34 pm

Few newbie questions

Post by someguy99 »

Hello
Few questions:
How do i remove an image from memory(after it was loaded)?
Is there a way to make Love2d wait untill the whole "scene"(images and music) are loaded,so that i wont see images appear after another?
And finally:
Is there a FOV in Love2d?(so that images "outside" of the screen(not visible) wont slow down my PC),or do i have to create it myself somehow?
(ps.i made a topic earlier,but looks like it hasnt posted)
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Few newbie questions

Post by bartbes »

  1. Set the variable to nil, and just wait for the GC (Garbage Collector)
  2. It draws when the loading is finished, loading is done synchronous.
  3. You can use setScissor (don't know about the performance part though)
User avatar
someguy99
Prole
Posts: 16
Joined: Tue Mar 17, 2009 5:34 pm

Re: Few newbie questions

Post by someguy99 »

Garbage Collector?
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Few newbie questions

Post by bartbes »

Yes, Lua features a Garbage Collector, it removes all unused variables (and functions) from memory. Where unused basically means that it is no longer referenced.
User avatar
someguy99
Prole
Posts: 16
Joined: Tue Mar 17, 2009 5:34 pm

Re: Few newbie questions

Post by someguy99 »

Ok.
"variablename = nil" doesnt work.
Its in the draw function.Inside an if-then.The if-then checks if the left mouse key was pressed in the specified location and loads new sprites,and discards the old images,with "variable name = nil".But instead of discarding it gives this error:
"ERROR:
No matching function for overloaded 'draw'
Stack traceback:
[C]: in function 'draw'
main.lua:40: in function <main.lua:22>"
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Few newbie questions

Post by bartbes »

Probably because you're still trying to draw using that variable, which is nil at that moment, and LÖVE can't draw nil values.
User avatar
someguy99
Prole
Posts: 16
Joined: Tue Mar 17, 2009 5:34 pm

Re: Few newbie questions

Post by someguy99 »

So what should i do to stop drawing?Any stopdraw function?
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Few newbie questions

Post by bartbes »

Stop trying to draw it in your draw function.
User avatar
someguy99
Prole
Posts: 16
Joined: Tue Mar 17, 2009 5:34 pm

Re: Few newbie questions

Post by someguy99 »

EDIT:OK HERES A WORKING MENU CODE:

Code: Select all

function load()
   font = love.graphics.newFont(love.default_font, 12)
   love.graphics.setFont(font)
   message = "Error:Some files are missing.Press Escape to exit."
   
   music = love.audio.newMusic("menu.ogg")
   love.audio.play(music,0)
   
   wallpaper = love.graphics.newImage("menu.png")
   play = love.graphics.newImage("play.png")
   options = love.graphics.newImage("options.png")
   about = love.graphics.newImage("about.png")
   exit = love.graphics.newImage("exit.png")
   play_selected = love.graphics.newImage("play_selected.png")
   options_selected = love.graphics.newImage("options_selected.png")
   about_selected = love.graphics.newImage("about_selected.png")
   exit_selected = love.graphics.newImage("exit_selected.png")
   
end


function draw()
   if love.keyboard.isDown(love.key_escape) then
   love.system.exit( ) 
   end
   
   if love.mouse.isDown(love.mouse_left) and x>60 and x<340 and y>660 and y<740 then 
   love.system.exit( ) 
   end
   
   if wallpaper ~= nil then
   love.graphics.draw(wallpaper,512,384)
   end
   
   x = love.mouse.getX( )
   y = love.mouse.getY( ) 
 
   if play_selected ~= nil and x>60 and x<340 and y>360 and y<440 then
   love.graphics.draw(play_selected,200,400)
   elseif play ~= nil then
   love.graphics.draw(play,200,400)
   end

   if options_selected ~= nil and x>60 and x<340 and y>460 and y<540 then
   love.graphics.draw(options_selected,200,500)
   elseif options ~= nil then
   love.graphics.draw(options,200,500)
   end
   
   if about_selected ~= nil and x>60 and x<340 and y>560 and y<640 then
   love.graphics.draw(about_selected,200,600)
   elseif about ~= nil then
   love.graphics.draw(about,200,600)
   end

   if exit_selected ~= nil and x>60 and x<340 and y>660 and y<740 then
   love.graphics.draw(exit_selected,200,700)
   elseif exit ~= nil then
   love.graphics.draw(exit,200,700)
   end

   if love.mouse.isDown(love.mouse_left) and x>60 and x<340 and y>360 and y<440 then
   love.mouse.setVisible(false)
   wallpaper = nil
   play = nil
   options = nil
   about = nil
   exit = nil
   play_selected = nil
   options_selected = nil
   about_selected = nil
   exit_selected = nil
   end

end
The menu.png is a 1024x768 image,the rest are 280x80.
When the mouse is on an option,it changes(colour,shape or whatever)
Anybody can use it if they wish.
Ill upload a .love file soon.
Last edited by someguy99 on Thu Mar 19, 2009 6:48 am, edited 1 time in total.
User avatar
someguy99
Prole
Posts: 16
Joined: Tue Mar 17, 2009 5:34 pm

Re: Few newbie questions

Post by someguy99 »

PS.Theres a useless '-' sign just after one of the 'else's.misspelled.
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests