Today I came across Corona SDK after using LÖVE for a while. I have stumbled upon a problem that I cannot seem to fix. The Bullets do spawn but they remain motionless. Is there another alternative to update every Bullet or am I doing something wrong?
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)
In LÖVE I could update every individual Bullet using:
function love.update(dt)
for _,v in ipairs(Bullets) do v:update(dt) end
end