[SOLVED]How to implement new levels correctly

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.
Post Reply
Markku
Prole
Posts: 3
Joined: Fri May 05, 2017 10:23 am

[SOLVED]How to implement new levels correctly

Post by Markku »

I can make a game level with load, update, draw and everything works (which is a miracle, thanks devs!).

However, if my character then should go to a new level with new graphics, music etc., how do I can start anew? I would need to save the progress for the character and then load new resources. Also, should I release memory etc. from previous level resources? Is there a recommended structure or tutorial for this...?

I tried to find this in Wiki and Google, but no luck...
Last edited by Markku on Fri May 05, 2017 3:34 pm, edited 1 time in total.
User avatar
RaycatRakittra
Prole
Posts: 22
Joined: Fri Sep 30, 2016 12:40 am
Location: Chicago, IL
Contact:

Re: How to implement new levels correctly

Post by RaycatRakittra »

Markku wrote: Fri May 05, 2017 10:35 am [...] However, if my character then should go to a new level with new graphics, music etc., how do I can start anew? [...] Also, should I release memory etc. from previous level resources? Is there a recommended structure or tutorial for this...?
It's your game. You decide what 'structure' you want to use.

An example of a simple implementation would keep track of the level number and just draw different things on the screen but, this is during gameplay; it's not a level select. A better implementation would be creating a sort of class for Levels. They would have their own load(), update(), and draw() functions that you would call in the main game loop. You could even include a cleanup() function for when you switch levels (though I don't think that memory should ever be an issue). An ever better implementation treats the levels as objects and registers them with a higher-order function that tells the game what level should be rendering. However, the last one is an opinion; you have to strike a balance with abstracting what would be tedious for you - the programmer - and what would essentially be a rocket launcher for an anthill.
Markku wrote: Fri May 05, 2017 10:35 am I would need to save the progress for the character and then load new resources.
Again, you decide what structure you want to use. Your character's position and state should be saved somewhere. If you want to implement some type of hot-swapping solution, it shouldn't be too difficult to load a new level around the player.
Sometimes, I can code things.
MasterLee
Party member
Posts: 141
Joined: Tue Mar 07, 2017 4:03 pm
Contact:

Re: How to implement new levels correctly

Post by MasterLee »

There is no need to release memory simple secure that there is no more reference to the objects.
On the other hand there is no real recommended structure for changing levels.
I use

Code: Select all

scene=engine.getScene(…
but that is specific i program my stuff
User avatar
OnACoffeeBreak
Prole
Posts: 28
Joined: Tue Apr 11, 2017 11:19 am

Re: How to implement new levels correctly

Post by OnACoffeeBreak »

I haven't used it myself yet, but wouldn't HUMP gamestate library be useful here?
Markku
Prole
Posts: 3
Joined: Fri May 05, 2017 10:23 am

Re: How to implement new levels correctly

Post by Markku »

Ok, thanks, I try to see if I can use those suggestions. Another way I see I could do this is that I make my own resource load function and in the beginning Löve calls it from love.load(), then I do it myself, when a level is complete. Let's see how this works...

Thanks!
Markku
Prole
Posts: 3
Joined: Fri May 05, 2017 10:23 am

Re: How to implement new levels correctly

Post by Markku »

...and after quick testing, one resource loading function seems to work. I just make a love.audio.stop() and then reload stuff to same variables, so when love.draw() works, it has new content to work with.

This is solved then...
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 141 guests