Reputation:
I am currently making my Plants vs Zombies using LOVE2D, only finishing the start state. The problem though is that option text won't show up, only the title does:
I made this in StartState.lua
:
StartState = Class{__includes = BaseState}
local option = 1
function StartState:update(dt)
if love.keyboard.wasPressed('up') then
if option == 1 then
option = 2
else
option = 1
end
elseif love.keyboard.wasPressed('down') then
if option == 2 then
option = 1
else
option = 2
end
end
if love.keyboard.wasPressed('enter') then
if option == 1 then
gStateMachine:change('play')
else
gStateMachine:change('quit')
end
end
end
function StartState:render()
local backgroundWidth = gTextures['start-background']:getWidth()
local backgroundHeight = gTextures['start-background']:getHeight()
love.graphics.draw(gTextures['start-background'], 0, 0, 0, VIRTUAL_WIDTH / (backgroundWidth - 1),
VIRTUAL_HEIGHT / (backgroundHeight - 1))
love.graphics.setFont(gFonts['medium'])
love.graphics.setColor(0/255, 0/255, 0/255, 255/255)
love.graphics.printf('Play', 0, VIRTUAL_HEIGHT + 5, VIRTUAL_WIDTH + 2, 'center')
love.graphics.printf('Quit', 0, VIRTUAL_HEIGHT + 35, VIRTUAL_WIDTH + 2, 'center')
if option == 1 then
love.graphics.setColor(255/255, 174/255, 201/255, 255/255)
love.graphics.printf('Play', 0, VIRTUAL_HEIGHT, VIRTUAL_WIDTH, 'center')
love.graphics.setColor(237/255, 28/255, 36/255, 255/255)
love.graphics.printf('Quit', 0, VIRTUAL_HEIGHT + 30, VIRTUAL_WIDTH, 'center')
else
love.graphics.setColor(237/255, 28/255, 36/255, 255/255)
love.graphics.printf('Play', 0, VIRTUAL_HEIGHT, VIRTUAL_WIDTH, 'center')
love.graphics.setColor(255/255, 174/255, 201/255, 255/255)
love.graphics.printf('Quit', 0, VIRTUAL_HEIGHT + 30, VIRTUAL_WIDTH, 'center')
end
love.graphics.setFont(gFonts['large'])
love.graphics.setColor(153/255, 217/255, 234/255, 128/255)
love.graphics.printf('Attack Them All', 0, VIRTUAL_HEIGHT / 2 - 50, VIRTUAL_WIDTH, 'center')
love.graphics.setColor(255/255, 255/255, 255/255, 255/255)
end
I even tried to get rid of the background to make sure if the text is at the back, but no, it is not there. I even tried changing the opacity, but still nothing. How do I fix it?
Upvotes: 0
Views: 294
Reputation:
Take a look back at your coordinates of the text. If you see misleading coordinates, try fixing it!
Upvotes: 0
Reputation: 344
You can only draw objects at the love.draw() callback, it must be executed periodically every time you want it to draw for the current frame
At your main.lua
file:
function love.update()
StartState:update(dt)
end
function love.draw()
StartState:render()
end
Upvotes: 1