particles.lua 597 B

12345678910111213141516171819202122232425262728293031
  1. local Particles = class()
  2. function Particles:init()
  3. self.particles = {}
  4. ctx.event:on('particle.create', f.cur(self.create, self))
  5. end
  6. function Particles:create(arg)
  7. local type = arg.kind
  8. for _ = 1, arg.count or 1 do
  9. local p = new(data.particle[type])
  10. p:activate()
  11. table.merge(arg.vars or {}, p)
  12. table.insert(self.particles, p)
  13. end
  14. end
  15. function Particles:update()
  16. for i = #self.particles, 1, -1 do
  17. local p = self.particles[i]
  18. if f.exe(p.update, p) then
  19. ctx.view:unregister(p)
  20. table.remove(self.particles, i)
  21. end
  22. end
  23. end
  24. return Particles