为什么我的文字不会在Love2D游戏中更新?

问题描述

我终于解决了有关文本未显示在游戏中的问题,现在下一个问题是它不会更新。应该发生的是,当我按向上和向下箭头键时,所选文本将更改,然后按Enter将使我进入新的状态,或者退出游戏。

我的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['large']) love.graphics.setColor(153/255,217/255,234/255,255/255) love.graphics.printf('Attack Them All',VIRTUAL_HEIGHT / 2 - 50,VIRTUAL_WIDTH,'center') love.graphics.setFont(gFonts['medium']) love.graphics.setColor(0/255,0/255,255/255) love.graphics.printf('Play',(VIRTUAL_HEIGHT / 2) + 2,VIRTUAL_WIDTH + 2,'center') love.graphics.printf('Quit',(VIRTUAL_HEIGHT / 2) + 22,'center') if option == 1 then love.graphics.setColor(255/255,174/255,201/255,255/255) love.graphics.printf('Play',(VIRTUAL_HEIGHT / 2),'center') love.graphics.setColor(237/255,28/255,36/255,255/255) love.graphics.printf('Quit',(VIRTUAL_HEIGHT / 2) + 20,'center') else love.graphics.setColor(237/255,'center') love.graphics.setColor(255/255,'center') end love.graphics.setColor(255/255,255/255,255/255) end 中的代码现在看起来像这样:

StateMachine

我已经在main.lua文件添加function love.load() love.graphics.setDefaultFilter('nearest','nearest') math.randomseed(os.time()) love.window.setTitle('Attack Them All') push:setupScreen(VIRTUAL_WIDTH,VIRTUAL_HEIGHT,WINDOW_WIDTH,WINDOW_HEIGHT,{ vsync = true,fullscreen = false,resizable = true }) gStateMachine = StateMachine { ['start'] = function() return StartState() end,['play'] = function() return PlayState() end,['quit'] = function() return QuitState() end } gStateMachine:change('start') end function love.update(dt) gStateMachine:update(dt) end

photoOutput(_:didFinishProcessingPhoto:error:)

我在做什么错了?

解决方法

love.keyboard.wasPressed不是标准的Love2D API。应该在代码的其他地方实现吗?首先检查。 然后尝试在应该执行代码的条件中放入print("condition xxx is verified"),然后在未验证条件的地方找到

示例:

if love.keyboard.wasPressed('up') then
   print("up is pressed")
   ...