player disappear after switching gamestate

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
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

player disappear after switching gamestate

Post 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!
User avatar
stampede247
Prole
Posts: 11
Joined: Thu May 02, 2013 8:21 pm
Location: United States
Contact:

Re: player disappear after switching gamestate

Post 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!
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

Re: player disappear after switching gamestate

Post 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.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest