ui_particleemitter.lua 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. local l_gfx = love.graphics
  2. -- particle emitter element
  3. -- made specifically for particle editor
  4. -- so it may not meet your needs
  5. ParticleEmitter = {}
  6. ParticleEmitter.__index = ParticleEmitter
  7. ParticleEmitter.ident = "ui_particleemitter"
  8. ParticleEmitter.name = "ParticleEmitter"
  9. ParticleEmitter.updateable = true
  10. ParticleEmitter.x = 0
  11. ParticleEmitter.y = 0
  12. ParticleEmitter.followMouse = false -- if true it will follow the cursor
  13. ParticleEmitter.mode = l_gfx.getBlendMode()
  14. function ParticleEmitter:new(name,tex)
  15. local self = {}
  16. setmetatable(self,ParticleEmitter)
  17. self.ps = l_gfx.newParticleSystem(tex,10)
  18. self.ps:setEmissionRate(1)
  19. self.ps:setEmitterLifetime(-1)
  20. self.ps:setSizes(1)
  21. self.ps:setParticleLifetime(1)
  22. if name ~= nil then self.name = name end
  23. return self
  24. end
  25. setmetatable(ParticleEmitter,{__index = UIElement})
  26. function ParticleEmitter:draw()
  27. local bm = l_gfx.getBlendMode()
  28. l_gfx.setBlendMode(self.mode)
  29. l_gfx.draw(self.ps)
  30. l_gfx.setBlendMode(bm)
  31. end
  32. function ParticleEmitter:update(dt)
  33. self.ps:update(dt)
  34. end
  35. function ParticleEmitter:mousemoved(x,y)
  36. if self.followMouse == true then
  37. self.ps:moveTo(x,y)
  38. end
  39. end