improvements to particles and animation can now have variable speed
This commit is contained in:
@@ -15,12 +15,13 @@ function Particle:new(x,y,particle_data)
|
||||
o.sprite_scale = particle_data.sprite_scale or o.sprite_scale
|
||||
o.sprite_tint = particle_data.sprite_tint or o.sprite_tint
|
||||
o.sprite_alpha = particle_data.sprite_alpha or o.sprite_alpha
|
||||
o.sprite_alpha_fade = particle_data.sprite_alpha_fade or false
|
||||
o.sprite_alpha_base = o.sprite_alpha
|
||||
|
||||
o.sprite_flip = particle_data.sprite_flip or o.sprite_flip
|
||||
o.animation_active = particle_data.animation_active or false
|
||||
|
||||
o.time = 0.5
|
||||
o.time = particle_data.time or nil
|
||||
if o.time ~= nil then o.time = o.time * game.framerate end
|
||||
|
||||
o.timer = 0
|
||||
|
||||
o.vel = {
|
||||
@@ -39,14 +40,12 @@ function Particle:new(x,y,particle_data)
|
||||
|
||||
-- animations
|
||||
if particle_data.animation ~= nil then
|
||||
o.body = Animation:new(particle_data.animation)
|
||||
o.body = Animation:new(particle_data.animation,particle_data.animation_speed)
|
||||
o:centerOffset(o.body)
|
||||
o:createBox(o.body)
|
||||
if not o.animation_active then
|
||||
o.body.speed = 0
|
||||
end
|
||||
end
|
||||
|
||||
-- particle id handled differently from other entities
|
||||
table.insert(LoadedObjects.Particles,o)
|
||||
o.id = #LoadedObjects.Particles
|
||||
|
||||
@@ -71,13 +70,12 @@ function Particle:kill()
|
||||
end
|
||||
|
||||
function Particle:handleAnimation()
|
||||
self.timer = self.timer + current_dt
|
||||
self.sprite_alpha = self.sprite_alpha_base*(self.time-self.timer)/self.time
|
||||
if self.light ~= nil then
|
||||
self:adjustLight()
|
||||
self.light.range = self.light_range * self.sprite_alpha/2
|
||||
self.timer = self.timer + 1
|
||||
|
||||
if self.sprite_alpha_fade ~= false then
|
||||
self.sprite_alpha = self.sprite_alpha_base*(self.time-self.timer)/self.time
|
||||
end
|
||||
if self.sprite_alpha < 0 then self:kill() end
|
||||
|
||||
if self.body ~= nil then
|
||||
self.body:animate()
|
||||
self:draw(self.body)
|
||||
@@ -93,6 +91,15 @@ function Particle:doPhysics()
|
||||
end
|
||||
-- move
|
||||
self:moveWithCollision()
|
||||
|
||||
if self.light ~= nil then
|
||||
self:adjustLight()
|
||||
self.light.range = self.light_range * self.sprite_alpha/2
|
||||
end
|
||||
|
||||
if self.time ~= nil then
|
||||
if self.timer >= self.time then self:kill() end
|
||||
end
|
||||
end
|
||||
|
||||
function Particle:debug()
|
||||
|
||||
Reference in New Issue
Block a user