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.
--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
--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
Yes, currentState and switchState do exist in other files. I had this running fine between Menu and Game state, but only started experiencing problems with Intro.
Hey!
Hope someone can help him, since it is something it's been bothering me for a while.
Also, I don't know about this but, you used TitleScreen in your introstate.lua, but you tried to call it "Intro" in main.lua, which is not defined nowhere in the introstate.lua
Again, Im new, but I'm just trying to help.
Hope someone with more knowledge helps you better!
Cheers!
Here is the .love file, not sure if it works? Didn't seem to work for me. So I included the bulk of the states system I have pre-coded. This is surely a frustrating black screen for a n00b like myself.
--statesystems.lua
oldState = "none"
currentState = "none"
function stateDrawCurrentState()
if currentState == "Game" then
GameDraw()
elseif currentState == "Menu" then
MenuDraw()
end
end
function stateGetCurrentStateInput()
if currentState == "Game" then
GameDoInput()
elseif currentState == "Menu" then
MenuDoInput()
end
end
function switchState(state)
if currentState ~= state then
oldState = currentState
if oldState == "Game" then
GameShutdown()
elseif oldState == "Menu" then
MenuShutdown()
end
currentState = state
-- if currentState == "Game" then
-- GameSetup()
-- elseif currentState == "Menu" then
-- MenuSetup()
-- end
end
end