HELP! GameStates from scratch. (Intro > Menu > Game)
Posted: Wed Apr 30, 2014 5:23 am
I'm a bit of a newbie. I;m having difficulty getting my gamestates to run properly. When I run I get a black screen. The issue seems to be from the Introstate based on my own assessment. Any help to get this to run would be much appreciated, my mental state is degrading.
Code: Select all
--main.lua
require "conf"
require "introstate"
require "menustate"
require "gamestate"
require "statesystems"
require "menubuttons"
function love.load()
switchState("Intro")
TitleScreen:start()
GameTitle = love.graphics.newImage ("images/hologram18.jpg")
CompanyLogo = love.graphics.newImage ("images/Shepherd001.jpg")
if currentState == "Intro" then
love.graphics.setBackgroundColor(0,0,0)
end
if currentState == "Menu" then
button_spawn(375, 175, "Start", "start")
button_spawn(375, 475, "Quit", "quit")
end
small = love.graphics.newFont(25)
medium = love.graphics.newFont(50)
large = love.graphics.newFont(80)
end
function love.update(dt)
mousex = love.mouse.getX()
mousey = love.mouse.getY()
if currentState == "Intro" then
TitleScreen.update(dt)
end
if currentState == "Menu" then
button_check()
end
-- stateDrawCurrentState()
-- stateGetCurrentStateInput()
end
function love.draw()
if currentState == "Intro" then
TitleScreen.draw()
end
if currentState == "Menu" then
button_draw()
end
if currentState == "Game" then
love.graphics.setFont(small)
love.graphics.print("Temp Game State", 325, 275)
end
end
function love.mousepressed(x,y,button)
if currentState == "Menu" then
button_click(x,y)
end
end
Code: Select all
--introstate.lua
TitleScreen = {}
local self = TitleScreen;
function TitleScreen.start()
self.objects = {}
self.co = coroutine.wrap(function()
wait(1)
self.objects[1] = love.graphics.draw(CompanyLogo, 200, 200)
wait(2)
self.objects[1] = nil
wait(1)
self.objects[1] = love.graphics.draw(GameTitle, 200, 200)
-- wait(0.5)
-- self.objects[2] = GameSubtitle.new()
wait(10)
switchState("Menu")
end)
end
function TitleScreen.update(dt)
self.co(dt)
end
function TitleScreen.draw()
for i = 1, #self.objects do
self.objects[i].draw()
end
end
function wait(seconds)
while seconds > 0 do
local dt = coroutine.yield(true)
seconds = seconds - dt
end
end