问题描述
我目前正在使用lovE2D制作植物大战僵尸,只是完成了开始状态。但是问题是选项文本不会显示,只有标题显示:
我在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'],VIRTUAL_WIDTH / (backgroundWidth - 1),VIRTUAL_HEIGHT / (backgroundHeight - 1))
love.graphics.setFont(gFonts['medium'])
love.graphics.setColor(0/255,0/255,255/255)
love.graphics.printf('Play',VIRTUAL_HEIGHT + 5,VIRTUAL_WIDTH + 2,'center')
love.graphics.printf('Quit',VIRTUAL_HEIGHT + 35,'center')
if option == 1 then
love.graphics.setColor(255/255,174/255,201/255,255/255)
love.graphics.printf('Play',VIRTUAL_HEIGHT,VIRTUAL_WIDTH,'center')
love.graphics.setColor(237/255,28/255,36/255,255/255)
love.graphics.printf('Quit',VIRTUAL_HEIGHT + 30,'center')
else
love.graphics.setColor(237/255,'center')
love.graphics.setColor(255/255,'center')
end
love.graphics.setFont(gFonts['large'])
love.graphics.setColor(153/255,217/255,234/255,128/255)
love.graphics.printf('Attack Them All',VIRTUAL_HEIGHT / 2 - 50,'center')
love.graphics.setColor(255/255,255/255,255/255)
end
我什至试图摆脱背景,以确保文本是否在背面,但不,它不在那里。我什至尝试更改不透明度,但仍然没有任何效果。我该如何解决?
解决方法
您只能在love.draw()回调中绘制对象,每次要为当前帧绘制对象时,都必须定期执行该对象
在您的main.lua
文件中:
function love.update()
StartState:update(dt)
end
function love.draw()
StartState:render()
end
,
回头看一下您的文本坐标。如果您看到误导性的坐标,请尝试修复它!