lua love2d, 弹药无法产生

我正在制作一款游戏,但是不知道为什么想要产生的“弹药”就是不出现!?

这是我的'Main':

require "scripts.player"
require "scripts.bullet"

function love.load()
bulletShoot = love.graphics.newImage("pics/bullet.png")
playerPic = love.graphics.newImage("pics/player.png")
background = love.graphics.newImage("pics/background.jpg")
player_load()
bullet.load()
end

function love.update(dt)
player_update(dt)
bullet.update(dt)
end

function love.draw()
love.graphics.draw(background, 0, 0)
bullet.draw()
player_draw()
end

我的“Player”,在这里我尝试调用它:

function player_shoot(dt)
playerShootTimer = playerShootTimer * dt
if(playerShootTimer > playerShootTimerLim) then
    if love.keyboard.isDown("space")then
        bullet.spawn(playerX + (playerWidth / 2) - (bullet.width / 2), playerY)
    end
  end
end

function player_update(dt)
player_move(dt)
player_boundary()
player_shoot(dt)
end

还有我的'Bullet',在这里我尝试绘制和产生它:

function bullet.spawn(x,y)
table.insert(bullet, {x = x, y = y})
end

function bullet.draw()
for i,v in ipairs(bullet) do
    love.graphics.draw(bulletShoot, v.x, v.y, bullet.width, bullet.height)
end
end

我尝试过的事情: - 我将弹药从调用 png 改成了一个填充的正方形 - 我从一个现有的(工作的)游戏中复制并粘贴了弹药类

这些事情都没用。 任何帮助都是有用的,谢谢!

点赞
用户336528
用户336528

问题似乎在于player_shoot函数中你正在将playerShootTimer乘以dt而不是加上它。

playerShootTimer = playerShootTimer + dt

我假设playerShootTimer初始值为0。然后如果它变得大于playerShootTimerLim并且按下了空格键,就会生成一个子弹。如果你想要允许玩家多次射击,你还需要在生成一个子弹之后将playerShootTimer重置为0。

if love.keyboard.isDown("space")then
    bullet.spawn(playerX + (playerWidth / 2) - (bullet.width / 2), playerY)
    playerShootTimer = 0
end
2017-04-26 05:05:19