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