lua love2d,不在子弹中繁殖

lua love2d,不在子弹中繁殖,lua,love2d,Lua,Love2d,我一直在做一个游戏,但由于某些原因,我试图在其中产生的子弹就是不起作用 这是我的“主要” 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.graph

我一直在做一个游戏,但由于某些原因,我试图在其中产生的子弹就是不起作用

这是我的“主要”

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
我试图称之为“玩家”的地方

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
还有我的“子弹”,我试着把它画出来

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 -我复制并粘贴了我制作的现有工作游戏中的bullet类

这些东西都没有用。
任何帮助都是有用的,谢谢

问题似乎在于,在玩家射击中,你将玩家的得分乘以dt,而不是将其相加

我假设playerShootTimer从零开始。然后你有,如果它变得比playerShootTimerLim更大并且空间被按下,产生一个子弹。如果你想让玩家射击多次,你还需要在产生子弹后将playerShootTimer重置为零

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

提供的代码仅包含几个函数定义。。请提供一个最小的可执行示例。我不太喜欢Lua内部,但在bullet.spawn中,您添加了一个设置了x和y成员的表,但在bullet.draw中,您循环使用bullet的每个成员,并尝试使用这些x和y变量进行绘制。如果我错了,请纠正我,但是该循环不也包括bullet.spawn和bullet.draw函数吗?
if love.keyboard.isDown("space")then
    bullet.spawn(playerX + (playerWidth / 2) - (bullet.width / 2), playerY)
    playerShootTimer = 0
end