I'm trying to get a Pause screen working, using HUMP for gamestates. I have a main level that I load into initially, and then when I hit P it switches to a Pause screen. The issue is when I hit P again to pop the pause gamestate off, I get a bunch of errors,
Code: Select all
Error
stack overflow
Traceback
[C]: in function 'getWidth'
gamestates/pause.lua:10: in function 'draw'
gamestates/pause.lua:12: in function 'draw'
gamestates/pause.lua:12: in function 'draw'
gamestates/pause.lua:12: in function 'draw'
gamestates/pause.lua:12: in function 'draw'
gamestates/pause.lua:12: in function 'draw'
gamestates/pause.lua:12: in function 'draw'
gamestates/pause.lua:12: in function 'draw'
...
gamestates/pause.lua:12: in function 'draw'
gamestates/pause.lua:12: in function 'draw'
gamestates/pause.lua:12: in function 'draw'
gamestates/pause.lua:12: in function 'draw'
gamestates/pause.lua:12: in function 'draw'
gamestates/pause.lua:12: in function 'draw'
gamestates/pause.lua:12: in function 'draw'
[C]: in function 'xpcall'
I can't for the life of me figure out whats happening.
gameLevel1.lua
Code: Select all
-- importing gamestate lib
Gamestate = require 'libs.hump.gamestate'
-- importing entities
local Entities = require 'entities.Entities'
local Entity = require 'entities.Entity'
-- Creating gamestate for level1
local gameLevel1 = Gamestate.new()
-- bringing in entities that we need [players, enemies, background, bullets]
local Player = require 'entities.player'
local BoxEnemy = require 'entities.boxEnemy'
local Map = require 'entities.level1map'
local Bullet = require 'entities.bullet'
-- switch to pause screen
function gameLevel1:enter()
current_state = gameLevel1
--initializing entities
Entities:enter()
Player:init()
Bullet:init()
BoxEnemy:init()
Map:init()
-- updating Entity list
Entities:addMany({Map, Player, BoxEnemy, Bullet})
end
-- update for each entity
function gameLevel1:update(dt)
Entities:update(dt)
function love.keypressed(key)
if Gamestate.current() ~= mgameLevel1 and key == 'p' then
Gamestate.push(pause)
end
end
end
function love.keypressed(key)
if Gamestate.current() ~= gameLevel1 and key == 'p' then
Gamestate.push(pause)
end
end
-- draws each entitiy
function gameLevel1:draw()
Entities:draw()
end
return gameLevel1
Pause.lua
Code: Select all
pause = Gamestate.new()
function pause:enter(from)
self.from = from -- record previous state
end
function pause:draw()
local w, h = love.graphics.getWidth(), love.graphics.getHeight()
-- draw previous screen
self.from:draw()
-- overlay with pause message
love.graphics.setColor(0,0,0, 100)
love.graphics.rectangle('fill', 0,0, w, h)
love.graphics.setColor(255,255,255)
love.graphics.printf('PAUSE', 0, h/2, w, 'center')
end
-- extending the example of Gamestate.push() above
function love.keypressed(key)
if key == 'p' then
return Gamestate.pop() -- return to previous state
end
end
return pause