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...
[SOLVED]How to implement new levels correctly
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[SOLVED]How to implement new levels correctly
Last edited by Markku on Fri May 05, 2017 3:34 pm, edited 1 time in total.
- RaycatRakittra
- Prole
- Posts: 22
- Joined: Fri Sep 30, 2016 12:40 am
- Location: Chicago, IL
- Contact:
Re: How to implement new levels correctly
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.
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.
Re: How to implement new levels correctly
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
but that is specific i program my stuff
On the other hand there is no real recommended structure for changing levels.
I use
Code: Select all
scene=engine.getScene(…
- OnACoffeeBreak
- Prole
- Posts: 28
- Joined: Tue Apr 11, 2017 11:19 am
Re: How to implement new levels correctly
I haven't used it myself yet, but wouldn't HUMP gamestate library be useful here?
Re: How to implement new levels correctly
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!
Thanks!
Re: How to implement new levels correctly
...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...
This is solved then...
Who is online
Users browsing this forum: Bing [Bot] and 3 guests