Page 1 of 1

player disappear after switching gamestate

Posted: Fri May 03, 2013 8:22 pm
by MadByte
Hi everyone,

I'm new and got a little problem here.
Here is my code so far.
StateProblem.love
If you run it you can switch to the titlescreen with escape and go back to the game with return. After you've switched from the gamescreen to the titlescreen and then back to the gamescreen the player disappeared and I have no clue why. Maybe there is a problem with the setState function but I can't find it.
Maybe one of you could help.

Maybe relevant snippets:

Code: Select all

-- Main

require("src.state")
require("src.world")
require("src.entity")

local State

function setState( newState )
  
  if State ~= nil then State:leave() end
  State = newState
  State:init()
  
end

Code: Select all

function gamescreen:init()
  World = world.new()
  player = entity.new( 100, 100 )
  World:add( player )
  require("src.player")
end

function gamescreen:update(dt)
  World:update(dt)
end

function gamescreen:draw()
  World:draw()
  love.graphics.setColor( 255, 255, 255 )
  love.graphics.print( "FPS: "..love.timer.getFPS(), 10, 10 )
end
Thanks in advance!

Re: player disappear after switching gamestate

Posted: Fri May 03, 2013 9:16 pm
by stampede247
Alright so I found the root of the problem but being so new to lua I'm not sure exactly how to fix it. Essentially what is happening is when you return to the room the entity that is created is just a generic entity. Or at least the generic entity draw function is getting called. If you put something in entity:draw() then it will show up when you return to the game. So I'm gonna guess something is wrong with your inheritance. I can't fix it though cuz I don't know how to set up inheritance in lua :P

Anyways hope that helps!

Re: player disappear after switching gamestate

Posted: Sat May 04, 2013 7:19 am
by MadByte
That was helpful, thanks,
anyway I can't figure out how to solve it either. mhh.

edit:
I changed now the way I load the entitys into the world so I skipped the problem.
Anyways I would be intrested in why it does not work with the entity class.