Delete chunk - love.filesystem.load

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.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Delete chunk - love.filesystem.load

Post by Robin » Thu Nov 21, 2013 11:59 am

Disclaimer: I only recommend releasing and reloading resources like that when it actually takes up a lot of RAM, I don't think 60MB is really that much to keep in memory all the time.

You'll want to use two functions per state, like this:

lvl.lua:

Code: Select all

function enter_lvl()
    blue_sun = newAnimation(love.graphics.newImage ("/images/blue_sun.png"), 512, 512, 0.1, 20)
end

function leave_lvl()
    blue_sun = nil
end

function draw_sun ()
blue_sun:draw (400, 300)
end
main.lua:

Code: Select all

require("lvl")
[... snip ...]
function love.mousepressed(x, y, button )
	if game_mode == "menu" then
		if button == "l" then
			game_mode = "space"
			enter_lvl()
		end
	end
	
	if game_mode == "space" then
		if button == "r" then
			leave_lvl()
			game_mode = "menu"
		end
	end
end
There are libraries you can use that make using states a bit more structured.
Help us help you: attach a .love.

User avatar
Volgoza
Prole
Posts: 26
Joined: Fri Jul 13, 2012 12:20 pm

Re: Delete chunk - love.filesystem.load

Post by Volgoza » Thu Nov 21, 2013 12:03 pm

Robin, it's work. thank you very much! :)
There are libraries you can use that make using states a bit more structured.
In what sense?

User avatar
Volgoza
Prole
Posts: 26
Joined: Fri Jul 13, 2012 12:20 pm

Re: Delete chunk - love.filesystem.load

Post by Volgoza » Thu Nov 21, 2013 12:07 pm

Code: Select all

Disclaimer: I only recommend releasing and reloading resources like that when it actually takes up a lot of RAM, I don't think 60MB is really that much to keep in memory all the time.
My game takes ~200 RAM and it no more 20% out of all graphic resources... So that, it very need for me.

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Delete chunk - love.filesystem.load

Post by Robin » Thu Nov 21, 2013 8:41 pm

Volgoza wrote:
There are libraries you can use that make using states a bit more structured.
In what sense?
They can do all the bookkeeping you now have to do manually (like calling enter_lvl and leave_lvl) automatically, as well as handle some more advanced features like state stacking, etc. I recommend using such a library for every game that's going to have more than two, three states.

Also, how much RAM does it use? 200MB? That's a lot, but quite doable on modern computers. Anyway, it's always a trade off, and this is your call.
Help us help you: attach a .love.

User avatar
Volgoza
Prole
Posts: 26
Joined: Fri Jul 13, 2012 12:20 pm

Re: Delete chunk - love.filesystem.load

Post by Volgoza » Fri Nov 22, 2013 8:27 am

Robin, i think, what i need can create game self, without libraries and next time used libraries. :)

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 13 guests