display.newEmitter()

Type Function
Library display.*
Return value EmitterObject
Revision 2016.2887
Keywords Particle Designer, newEmitter
See also EmitterObject:start()
EmitterObject:stop()
EmitterObject:pause()

Overview

This function is used to create an EmitterObject, used to display particle effects created with Particle Designer.

Syntax

display.newEmitter( emitterParams [, baseDir] )
emitterParams (required)

String. The decoded parameters as outputted by Particle Designer in JSON format.

baseDir (optional)

Constant. Specifies the base directory where the particle emitter image file is located. Options include system.ResourceDirectory, system.DocumentsDirectory, system.TemporaryDirectory and system.CachesDirectory. Default is system.ResourceDirectory.

Example

-- Require the JSON library for decoding purposes
local json = require "json"

-- Read the exported Particle Designer file (JSON) into a string
local filePath = system.pathForFile( "fire.json" )
local f = io.open( filePath, "r" )
local fileData = f:read( "*a" )
f:close()

-- Decode the string
local emitterParams = json.decode( fileData )

-- Create the emitter with the decoded parameters
local emitter1 = display.newEmitter( emitterParams )

-- Center the emitter within the content area
emitter1.x = display.contentCenterX
emitter1.y = display.contentCenterY