Gamestate problem

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
User avatar
Davidobot
Party member
Posts: 1150
Joined: Sat Mar 31, 2012 5:18 am
Location: Game-Dev. Land
Contact:

Gamestate problem

Post by Davidobot » Thu Apr 05, 2012 5:47 am

How do you make the game draw a whole seperate scene and then go back to the original one. Eg: In a RPG game when you encounter a monster, the game switches the scene to battle and then after the battle is over it does back to the room. Post if you want me to upload the .love of the game I am talking about.
My library:
LovelyMoon

Check out my current project:
Raycaster

Oh hey, I have a website now!

User avatar
trubblegum
Party member
Posts: 192
Joined: Wed Feb 22, 2012 10:40 pm

Re: Gamestate problem

Post by trubblegum » Thu Apr 05, 2012 7:29 am

The simplest way seems to be to recreate the way LÖVE does it.
Something like :

Code: Select all

state = {}

state.menu = {}
state.menu.load = function(this) currentstate = this end
state.menu.update = function(dt) ... end
state.menu.draw = function() ... end

state.battle = {}
state.battle.load = function(this) currentstate = this end
... -- as above, and repeat for each state

love.load = function() currentstate = state.menu end
love.update = function(dt) currentstate.update(dt) end
love.draw = function() currentstate.draw() end
Then, to switch states :

Code: Select all

state.battle:load() -- or whatever your next state is
Obviously, you want a more elegant constructor, but the principle works well.

User avatar
Davidobot
Party member
Posts: 1150
Joined: Sat Mar 31, 2012 5:18 am
Location: Game-Dev. Land
Contact:

Re: Gamestate problem

Post by Davidobot » Thu Apr 05, 2012 9:50 am

trubblegum wrote:The simplest way seems to be to recreate the way LÖVE does it.
Something like :

Code: Select all

state = {}

state.menu = {}
state.menu.load = function(this) currentstate = this end
state.menu.update = function(dt) ... end
state.menu.draw = function() ... end

state.battle = {}
state.battle.load = function(this) currentstate = this end
... -- as above, and repeat for each state

love.load = function() currentstate = state.menu end
love.update = function(dt) currentstate.update(dt) end
love.draw = function() currentstate.draw() end
Then, to switch states :

Code: Select all

state.battle:load() -- or whatever your next state is
Obviously, you want a more elegant constructor, but the principle works well.
Thanks, +1 to you.
My library:
LovelyMoon

Check out my current project:
Raycaster

Oh hey, I have a website now!

Post Reply

Who is online

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