Page 1 of 1
credits keep crashing
Posted: Tue Jul 07, 2015 8:10 pm
by CanadianGamer
Hi guys
so I'm making this game but whenever I try to test the credits It crashes anyone know why
Re: credits keep crashing
Posted: Tue Jul 07, 2015 9:38 pm
by Eamonn
Whoops, seems like we need some assets, first. font1.ttf, font2.ttf and background.png
I'll work on finding a solution and edit this post if I find one, but could you please upload some assets? You could zip the files and just upload the archive to the forums or Google Drive or something.
Re: credits keep crashing
Posted: Tue Jul 07, 2015 9:46 pm
by CanadianGamer
sorry for bothering you I figured it out
Re: credits keep crashing
Posted: Tue Jul 07, 2015 9:52 pm
by Eamonn
CanadianGamer wrote:sorry for bothering you I figured it out
The for loop in the credits menu was causing the problem. I fixed it using a simple gamestate variable, to replace your title variable. Here's the code anyway:
main.lua:
Code: Select all
require('credits')
gamestate = 'title'
function love.load()
--backgroundImg = love.graphics.newImage('assets/background.png')
title = true
--font1 = love.graphics.newFont('assets/font1.ttf', 125)
--font2 = love.graphics.newFont('assets/font2.ttf', 50)
end
function love.update()
mouseX = love.mouse.getX()
mouseY = love.mouse.getY()
mouseIsPressed = love.mouse.isDown('l')
--play button
if gamestate == 'title' then
if mouseX >= 100 and
mouseX <= 210 and
mouseY >= 200 and
mouseY <= 240 and
mouseIsPressed == true then
gamestate = 'play'
--help button
elseif mouseX >= 100 and
mouseX <= 210 and
mouseY >= 250 and
mouseY <= 290 and
mouseIsPressed == true then
gamestate = 'help'
--credits button
elseif mouseX >= 100 and
mouseX <= 300 and
mouseY >= 300 and
mouseY <= 340 and
mouseIsPressed == true then
love.graphics.setNewFont(50)
gamestate = 'credits'
--quit button
elseif mouseX >= 100 and
mouseX <= 210 and
mouseY >= 350 and
mouseY <= 390 and
mouseIsPressed == true then
love.event.quit()
end
end
if gamestate == 'credits' then
-- Some form of credits updating
elseif gamestate == 'title' then
-- Some form of title updating
elseif gamestate == 'help' then
-- Some form of help updating
elseif gamestate == 'play' then
-- Some form of play upating
end
end
function love.draw()
--love.graphics.draw(backgroundImg, 0, 0)
if gamestate == 'title' then
love.graphics.setNewFont(20)
love.graphics.print('Ninja Dodge', 20, 20)
love.graphics.setNewFont(40)
love.graphics.print('Play', 100, 200)
love.graphics.print('Help', 100, 250)
love.graphics.print('Credits', 100, 300)
love.graphics.print('Quit', 100, 350)
elseif gamestate == 'credits' then
credits()
end
love.graphics.print(mouseX, 100, 100)
end
credits.lua:
Code: Select all
-- credits
isOn = true
function credits()
if gamestate == 'credits' then
keyDown = love.keyboard.isDown('escape')
if keyDown == true then
isOn = false
end
love.graphics.print('coded by: CanadianGamer', 30, 30)
love.graphics.print('ideas by: CanadianGamer', 30, 70)
love.graphics.print('everything else by: CanadianGamer', 30, 110)
end
end
You were also calling some love.draw() functions in love.update(dt). Be sure to separate drawing and updating code into separate functions ( eg credits_load(), credits_update(dt), credits_draw() )
Have a great day!