今天我在使用 LÖVE 一段时间后遇到了 Corona SDK。我偶然发现了一个我似乎无法解决的问题。子弹确实会生成,但它们仍然一动不动。是否有另一种方法可以更新每个 Bullet,或者我做错了什么?
Bullets = {}
Bullets.__index = Bullets
function Bullets.new()
local this = {}
this.x = Player.x
this.remove = false
this.dir = math.random(1,2)
this.timer = 0
this.velocity = math.random(2,5)
if this.dir == 1 then
this.y = display.actualContentHeight
elseif this.dir == 2 then
this.y = 0
end
this.rect = display.newRect(this.x,this.y,math.random(5,10),math.random(5,10))
this.rect:setFillColor(0)
return setmetatable(this,Bullets)
end
function Bullets.update(self,event)
self:move()
end
function Bullets.move(self)
if self.dir == 1 then
self.y = self.y + self.velocity
elseif self.dir == 2 then
self.y = self.y - self.velocity
end
end
function Bullets.destroy(self)
self.remove = true
end
Bullets.enterFrame = Bullets.update
Runtime:addEventListener("enterFrame",Bullets)
timer.performWithDelay(500,Bullets.new,0)
在 LÖVE 中,我可以使用以下方法更新每个 Bullet:
function love.update(dt)
for _,v in ipairs(Bullets) do v:update(dt) end
end