zoetrope / tests / emitters.lua

The default branch has multiple heads

require 'zoetrope'

RedParticle = Fill:extend{ width = 16, height = 16, fill = { 255, 0, 0, 128 } }

Emitters = TestApp:extend{
	title = 'Particle Emitter',

	onNew = function (self)
		self.emitter = Emitter:new{ x = 350, y = 250, width = 100, height = 100 }
		self.emitter.min = { velocity = { x = -500, y = -500, rotation = math.pi / 4 }, alpha = 0.25 }
		self.emitter.max = { velocity = { x = 500, y = 500, rotation = 4 * math.pi }, alpha = 0.75 }
		self.emitter.period = 0.05

		for i = 1, 400 do
			self.emitter:add(Fill:new{ width = 16, height = 16, fill = {0, 0, 255, 128} })
		end

		self.emitter:loadParticles(RedParticle, 400)
		self.emitter:loadParticles(RedParticle:extend{ fill = {0, 255, 0, 128} }, 400)

		self:add(self.emitter)

		self:add(Text:new
		{
			x = 10, y = 550, width = 550, font = 14,
			text = 'Zoetrope\'s particle emitters are similar to LOVE\'s, but each particle can be ' ..
				   'a sprite with custom code. Press the space bar to explode all particles at once.'
		})
	end,

	onUpdate = function (self, elapsed)
		if the.keys:justPressed(' ') then
			self.emitter:emit(#self.emitter.sprites)
		end
	end
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.