I am trying to use an emitter for an engine on a spaceship. We scale the ship in the game, but the engine emitters do not respect the scale of the group and stay at full size. Is it not possible to scale emitters? Has anyone else tried this?
you are right. i’ve same problem, emiiters are not scaled properly - emiiter is scaled but particles sprites are not.
you are right. i’ve same problem, emiiters are not scaled properly - emiiter is scaled but particles sprites are not.
Hi, experiencing the same troubles. Did you solved it somehow?
Thanks
Hi @Vaclav Plajt,
Can you post your basic emitter setup code, and show how you’re trying to scale it? Please surround the code with “lua” tags for clarity.
[lua] ... [/lua]
Thanks,
Brent
Hi @Brent,
please look at this image https://plus.google.com/u/0/photos/108222190029462316740/albums/6107221847944992529/6107222154914916290?pid=6107222154914916290&oid=108222190029462316740
It’s a screenshots from my current project. Around the middle of the image is a black circle with somewhat light center. The black circle is the wrongly scaled particle effect. The point is that the emitter is inserted into the same layer (display group) as images of all other items placed on the map. It can be easily verified when map is moved. The emitter have to move the same way as other objects in the group which it does. Unfortunately it is not always true for scale.
Here is the piece of code where the emitter is created (sorry for wrong spelling):
[lua] if(self.lastHitEmmiterName == emitterName) then emitter = self.lastHitEmmiter; else local x,y = self.map.isoGrid:isoToCart(self.r,self.u); emitter = require("ui.particles").newEmitter(emitterName); self.layer:insert(emitter); -- the same layer (group) as for other buildings graphics emitter.x = x; emitter.y = y-32; self.lastHitEmmiter = emitter; self.lastHitEmmiterName = emitterName; self.hitEmitterBaseDuration = emitter.duration; end emitter.duration = damage\*self.hitEmitterBaseDuration; emitter:start(); [/lua]
Looks like i don’t know how to properly use the [lua] … [/lua] tags
Hi Vaclav,
I did some testing, and you are correct that the actual particles emitted do not scale automatically with the display group. This should probably be fixed eventually, but in the meantime, can you just adjust the start and finish particle size manually? For example, if your JSON particle definition has these:
"startParticleSize": 50.95, "finishParticleSize": 64,
…you can read these properties in your Lua code like this:
[lua]
local sizeStart = myEmitter.startParticleSize
local sizeFinish = myEmitter.finishParticleSize
[/lua]
Then, if you scale the entire group by 0.7, try this:
[lua]
myEmitter.startParticleSize = sizeStart*0.7
myEmitter.finishParticleSize = sizeFinish*0.7
[/lua]
Please try this and report back your results.
Brent
Hello Brent,
sorry for delay. I tried what you suggested. It works, see the code below. Emitter parameters startParticleSizeVariance and finishParticleSizeVariance need to be scaled too. Since they are not relative to start and finish particle sizes.
The bigger problem is how to get scale value for nested groups. I need this because groups will scale all their children including another groups. So I guess I have to to traverse, using: [lua] group.parent [/lua] From group which includes your emitter to the top level group (Stage). And calculate scale by multiplying with all scales along the way. Is it right? Or is there more simple solution? Functions like [lua] displayObject:contentToLocal() [/lua] or [lua] displayObject:localToContent() [/lua] for scale might be handy.
[lua]
– create new group
local g = display.newGroup();
– parameters
local w,h = 200,200;
local cx,cy = display.screenOriginX+0.5*w,display.contentCenterY;
local scale = 0.25;
– add backround
local back = display.newRect(g, cx, cy,w, h);
back:setFillColor(1.0);
– Read the exported Particle Designer file (JSON) into a string
local json = require “json”
local filePath = system.pathForFile( “enemy_missile.json” )
local f = io.open( filePath, “r” )
local fileData = f:read( “*a” )
f:close();
– Decode the string
local emitterParams = json.decode( fileData )
emitterParams.duration = -1; – loop forever
– Create the emitter with the decoded parameters
local emitter = display.newEmitter( emitterParams )
g:insert(emitter);
– set emitters position
emitter.x = cx;
emitter.y = cy;
– set scale
g.xScale = scale;
g.yScale = scale;
– scale size params to emitted particles
emitter.startParticleSize = emitterParams.startParticleSize*scale;
emitter.finishParticleSize = emitterParams.finishParticleSize*scale;
emitter.startParticleSizeVariance = emitterParams.startParticleSizeVariance*scale;
emitter.startParticleSizeVariance = emitterParams.finishParticleSizeVariance*scale;
[/lua]
The emitter json def:
{ "startColorAlpha" : 1, "startParticleSizeVariance" : 7, "startColorGreen" : 0.9999999, "rotatePerSecond" : 0, "radialAcceleration" : -100, "yCoordFlipped" : -1, "emitterType" : 0, "blendFuncSource" : 770, "finishColorVarianceAlpha" : 0, "rotationEnd" : 0, "startColorVarianceBlue" : 0, "rotatePerSecondVariance" : 360, "particleLifespan" : 0.07000000000000001, "minRadius" : 118.82, "configName" : "enemy\_missile", "tangentialAcceleration" : -0, "rotationStart" : 0, "startColorVarianceGreen" : 0, "speed" : 130, "minRadiusVariance" : 0, "finishColorVarianceBlue" : 0, "finishColorBlue" : 0.9999999, "finishColorGreen" : 0.9999999, "blendFuncDestination" : 771, "finishColorAlpha" : 0.77, "sourcePositionVariancex" : 0, "startParticleSize" : 35, "sourcePositionVariancey" : 4, "startColorRed" : 0.9999966, "finishColorVarianceRed" : 0, "absolutePosition" : false, "textureFileName" : "enemy\_missile.png", "startColorVarianceAlpha" : 0, "maxParticles" : 15, "finishColorVarianceGreen" : 0, "finishParticleSize" : 5, "duration" : 0.1, "startColorVarianceRed" : 0, "finishColorRed" : 0.9999966, "gravityx" : 0, "maxRadiusVariance" : 0, "finishParticleSizeVariance" : 5, "gravityy" : 100, "rotationEndVariance" : 0, "startColorBlue" : 0.9999999, "rotationStartVariance" : 0, "speedVariance" : 30, "radialAccelVariance" : 100, "textureImageData" : "", "tangentialAccelVariance" : -0, "particleLifespanVariance" : 0.5, "angleVariance" : -360, "angle" : -0, "maxRadius" : 141.83 }
Hi @Vaclav,
Yes, if you have multiple nested groups, and you need to scale them up and down in relation to each other, then I think you’ll need to traverse through the groups to determine the actual scale of one particular group. But, with a little clever math, this should be fairly easy to do.
Brent
Hi, experiencing the same troubles. Did you solved it somehow?
Thanks
Hi @Vaclav Plajt,
Can you post your basic emitter setup code, and show how you’re trying to scale it? Please surround the code with “lua” tags for clarity.
[lua] ... [/lua]
Thanks,
Brent
Hi @Brent,
please look at this image https://plus.google.com/u/0/photos/108222190029462316740/albums/6107221847944992529/6107222154914916290?pid=6107222154914916290&oid=108222190029462316740
It’s a screenshots from my current project. Around the middle of the image is a black circle with somewhat light center. The black circle is the wrongly scaled particle effect. The point is that the emitter is inserted into the same layer (display group) as images of all other items placed on the map. It can be easily verified when map is moved. The emitter have to move the same way as other objects in the group which it does. Unfortunately it is not always true for scale.
Here is the piece of code where the emitter is created (sorry for wrong spelling):
[lua] if(self.lastHitEmmiterName == emitterName) then emitter = self.lastHitEmmiter; else local x,y = self.map.isoGrid:isoToCart(self.r,self.u); emitter = require("ui.particles").newEmitter(emitterName); self.layer:insert(emitter); -- the same layer (group) as for other buildings graphics emitter.x = x; emitter.y = y-32; self.lastHitEmmiter = emitter; self.lastHitEmmiterName = emitterName; self.hitEmitterBaseDuration = emitter.duration; end emitter.duration = damage\*self.hitEmitterBaseDuration; emitter:start(); [/lua]
Looks like i don’t know how to properly use the [lua] … [/lua] tags
Hi Vaclav,
I did some testing, and you are correct that the actual particles emitted do not scale automatically with the display group. This should probably be fixed eventually, but in the meantime, can you just adjust the start and finish particle size manually? For example, if your JSON particle definition has these:
"startParticleSize": 50.95, "finishParticleSize": 64,
…you can read these properties in your Lua code like this:
[lua]
local sizeStart = myEmitter.startParticleSize
local sizeFinish = myEmitter.finishParticleSize
[/lua]
Then, if you scale the entire group by 0.7, try this:
[lua]
myEmitter.startParticleSize = sizeStart*0.7
myEmitter.finishParticleSize = sizeFinish*0.7
[/lua]
Please try this and report back your results.
Brent
Hello Brent,
sorry for delay. I tried what you suggested. It works, see the code below. Emitter parameters startParticleSizeVariance and finishParticleSizeVariance need to be scaled too. Since they are not relative to start and finish particle sizes.
The bigger problem is how to get scale value for nested groups. I need this because groups will scale all their children including another groups. So I guess I have to to traverse, using: [lua] group.parent [/lua] From group which includes your emitter to the top level group (Stage). And calculate scale by multiplying with all scales along the way. Is it right? Or is there more simple solution? Functions like [lua] displayObject:contentToLocal() [/lua] or [lua] displayObject:localToContent() [/lua] for scale might be handy.
[lua]
– create new group
local g = display.newGroup();
– parameters
local w,h = 200,200;
local cx,cy = display.screenOriginX+0.5*w,display.contentCenterY;
local scale = 0.25;
– add backround
local back = display.newRect(g, cx, cy,w, h);
back:setFillColor(1.0);
– Read the exported Particle Designer file (JSON) into a string
local json = require “json”
local filePath = system.pathForFile( “enemy_missile.json” )
local f = io.open( filePath, “r” )
local fileData = f:read( “*a” )
f:close();
– Decode the string
local emitterParams = json.decode( fileData )
emitterParams.duration = -1; – loop forever
– Create the emitter with the decoded parameters
local emitter = display.newEmitter( emitterParams )
g:insert(emitter);
– set emitters position
emitter.x = cx;
emitter.y = cy;
– set scale
g.xScale = scale;
g.yScale = scale;
– scale size params to emitted particles
emitter.startParticleSize = emitterParams.startParticleSize*scale;
emitter.finishParticleSize = emitterParams.finishParticleSize*scale;
emitter.startParticleSizeVariance = emitterParams.startParticleSizeVariance*scale;
emitter.startParticleSizeVariance = emitterParams.finishParticleSizeVariance*scale;
[/lua]
The emitter json def:
{ "startColorAlpha" : 1, "startParticleSizeVariance" : 7, "startColorGreen" : 0.9999999, "rotatePerSecond" : 0, "radialAcceleration" : -100, "yCoordFlipped" : -1, "emitterType" : 0, "blendFuncSource" : 770, "finishColorVarianceAlpha" : 0, "rotationEnd" : 0, "startColorVarianceBlue" : 0, "rotatePerSecondVariance" : 360, "particleLifespan" : 0.07000000000000001, "minRadius" : 118.82, "configName" : "enemy\_missile", "tangentialAcceleration" : -0, "rotationStart" : 0, "startColorVarianceGreen" : 0, "speed" : 130, "minRadiusVariance" : 0, "finishColorVarianceBlue" : 0, "finishColorBlue" : 0.9999999, "finishColorGreen" : 0.9999999, "blendFuncDestination" : 771, "finishColorAlpha" : 0.77, "sourcePositionVariancex" : 0, "startParticleSize" : 35, "sourcePositionVariancey" : 4, "startColorRed" : 0.9999966, "finishColorVarianceRed" : 0, "absolutePosition" : false, "textureFileName" : "enemy\_missile.png", "startColorVarianceAlpha" : 0, "maxParticles" : 15, "finishColorVarianceGreen" : 0, "finishParticleSize" : 5, "duration" : 0.1, "startColorVarianceRed" : 0, "finishColorRed" : 0.9999966, "gravityx" : 0, "maxRadiusVariance" : 0, "finishParticleSizeVariance" : 5, "gravityy" : 100, "rotationEndVariance" : 0, "startColorBlue" : 0.9999999, "rotationStartVariance" : 0, "speedVariance" : 30, "radialAccelVariance" : 100, "textureImageData" : "", "tangentialAccelVariance" : -0, "particleLifespanVariance" : 0.5, "angleVariance" : -360, "angle" : -0, "maxRadius" : 141.83 }
Hi @Vaclav,
Yes, if you have multiple nested groups, and you need to scale them up and down in relation to each other, then I think you’ll need to traverse through the groups to determine the actual scale of one particular group. But, with a little clever math, this should be fairly easy to do.
Brent