Switching gamestates with HUMP
Posted: Wed Dec 23, 2015 4:41 am
Hello. This is my first forum post, so please be gentle. For the first time I've run into a problem that I can't solve via Google and the Wiki. I'm trying to proof-of-concept a simple main menu using HUMP gamestates. I can switch from the main menu to the placeholder screen for my "new game" introduction just fine. However,when I click the mouse button on the "intro" state screen, it fails to return me back to the menu state properly. Everything else works fine, I'm just stuck trying to return to the main menu state and have it display and be interacted with properly.
If anyone can spoonfeed me on how to properly use HUMP gamestates, I'll be very thankful. If not, well I'll try moving on to something else like Polygamy or Stateful. Thanks in advance guys!
LÖVE,
CaptainSwordsman
Code: Select all
Gamestate = require "hump.gamestate"
local menu = {}
local game = {}
local intro = {}
function menu:init()
bgImg = love.graphics.newImage('assets/gfx/mmbg.png')
menuOp = love.graphics.newImage('assets/gfx/options_menu.png')
end
function menu:enter()
menu:update()
end
function menu:update()
end
function menu:draw()
love.graphics.draw(bgImg, 0, 0)
love.graphics.draw(menuOp, 256, 240)
if continuePressed == true then
love.graphics.print('continuePressed', 10, 10)
elseif optionsPressed == true then
love.graphics.print('optionsPressed', 10, 10)
end
end
function menu:mousepressed(x, y, button)
if button == 'l' then
if x > 256 and x < 384 and y > 240 and y < 288 then
return Gamestate.switch(intro)
elseif x > 256 and x < 384 and y > 298 and y < 346 then
continuePressed = true
elseif x > 256 and x < 384 and y > 356 and y < 404 then
optionsPressed = true
end
end
intro:update()
end
function menu:mousereleased(x, y, button)
if button == 'l' then
continuePressed = false
optionsPressed = false
end
end
function intro:init()
introImg = love.graphics.newImage('assets/gfx/newGameScreen.png')
backButton = love.graphics.newImage('assets/gfx/backButton.png')
end
function intro:enter()
intro:update()
end
function intro:update()
end
--This function will of course be replaced when the actual intro sequence is coded
function intro:draw()
love.graphics.draw(introImg, 0, 0)
love.graphics.draw(backButton, 256, 240)
end
--This function will similarly be deleted
function intro:mousepressed(x, y, button)
if button == '1' then
return Gamestate.switch(menu)
end
end
function game:update(dt)
--
end
function love.load()
Gamestate.registerEvents()
Gamestate.switch(menu)
end
LÖVE,
CaptainSwordsman