How can I scale particles?

Hi,

I’m NOT using Corona’s auto-sizing for my app. in other words, I’m literally using the pixel resolution of the device directly to determine where to place my objects and how to determine the size of objects myself.

The problem I’ve encountered is that I don’t know how to properly scale a particle effect, since particleEmitter:scale(__,___) does not work as it does for other display objects.

Just for added information, here is my code to create a particle display object.

local emitterParams = json.decode( particleDataFromFile ) local emitter = display.newEmitter( emitterParams )

The following DOES NOT WORK. But it should.

xScale=deviceHorizontalResolution/2048 -- 2048 = particle is right size at 2048W yScale=deviceVerticalResolution/1536 -- 1536 = particle is right size at 1536H emitter:scale(xScale,yScale) -- does not work

Any help is very much appreciated.

Hi Troy,

You should adjust the properties of the emitter particles and the scale of the emitter itself. Both are actually crucial: the first adjusts the particles, the second adjusts the “area” in which the particles are spawned.

So, if you want to increase your particle emitter by 2x in overall scale, you should scale the emitter by 2.0. Then you should also adjust the “startParticleSize” and “finishParticleSize” of the particles by 2x what the core/initial values are (so, if you’ve set those to like 34.5 and 78.97 respectively, double those to 69 and 157.94).

See here for a list of properties.

https://docs.coronalabs.com/api/type/EmitterObject/index.html

Brent

P.S. - It’s on my to-do list to improve our documentation on this, and provide better descriptions of what each property actually does.

Should my scaling code above then be apparent after changing the start and end sizes of the particles, or will I need to scale the emitter size from the editor before exporting and if so, would that mean that I’d need a separate effects file for each possible resolution?

No need for separate JSON files… just set the properties directly. In fact, JSON isn’t even really required to set up emitter properties… again, that isn’t really obvious in our docs and it’s something I intend to fix.

Brent

Hi Troy,

You should adjust the properties of the emitter particles and the scale of the emitter itself. Both are actually crucial: the first adjusts the particles, the second adjusts the “area” in which the particles are spawned.

So, if you want to increase your particle emitter by 2x in overall scale, you should scale the emitter by 2.0. Then you should also adjust the “startParticleSize” and “finishParticleSize” of the particles by 2x what the core/initial values are (so, if you’ve set those to like 34.5 and 78.97 respectively, double those to 69 and 157.94).

See here for a list of properties.

https://docs.coronalabs.com/api/type/EmitterObject/index.html

Brent

P.S. - It’s on my to-do list to improve our documentation on this, and provide better descriptions of what each property actually does.

Should my scaling code above then be apparent after changing the start and end sizes of the particles, or will I need to scale the emitter size from the editor before exporting and if so, would that mean that I’d need a separate effects file for each possible resolution?

No need for separate JSON files… just set the properties directly. In fact, JSON isn’t even really required to set up emitter properties… again, that isn’t really obvious in our docs and it’s something I intend to fix.

Brent