[RESOLVED] Particle Candy & Storyboard: what's the best way to put it all together?

Now that all I have left to do is to juice up and sparkle up my current project before submitting to app store, I finally picked up Particle Candy (which I bought something like a year ago.) I can’t believe I haven’t used it sooner. It is great. I started off fooling around with the sample code, then read the tutorial & quickstart on x-pressive website. I now understand the basics to get my particle effects to appear when & where I want them to show up. I’m excited.

Now I’d like to make sure I go about implementing this in a smart way. I use Storyboard API to manage different scenes, so I looked at Storyboard sample code that comes with the Particle Candy – but I’m not sure if I want to create particle types (that defines the properties of each different particle effects) as globals in main lua. I’m wondering what might be the true wisdom in doing so.

For now, I’m doing the following:

Up top where I require other modules and forward declare variables, I have:

local Particles = require("lib\_particle\_candy")  
local PCMain  

Inside createScene function, I do:

  1. Create emitters (Edit: with autodestroy set to false, because I don’t want to recreate the emitters that I would use repeatedly)
  2. Define particle type properties
  3. Feed emitters (i.e., AttachParticleType)
  4. Create newImageRect objects with the images I use in particle type and set them to alpha. This basically preloads the particle images as suggested in http://www.x-pressive.com/ParticleCandy_Corona/tutorials.html

Inside enterScene function, I have:

local function PCMain( event )  
 -- UPDATE PARTICLES  
 Particles.Update()  
end  
Runtime:addEventListener( "enterFrame", PCMain )  

Inside game logics, wherever I want a specific particle effects to be triggered, I call StartEmitter function.

Inside exitScene function, I have:

Runtime:removeEventListener( "enterFrame", PCMain )  
Particles.CleanUp()  

Is this a good way to manage the Particle Candy effects with Storyboard API? I’d very much appreciate hearing some insight and wisdom regarding this.

Naomi [import]uid: 67217 topic_id: 33431 reply_id: 333431[/import]

That seems to make sense to me. I always advise people that for things that belong to that scene, if you create it in enterScene() remove it in exitScene() so what you’ve done seems to make sense.

[import]uid: 199310 topic_id: 33431 reply_id: 132797[/import]

Thank you for the feedback, Rob. I appreciate it.

In the storyboard sample code that comes with Particle Candy, what I do in createScene is actually done in enterScene, and I’m wondering if I should move all Particle Candy related code that I currently have in createScene to enterScene. Is it all about personal preference or is there a good reason why I should. And if it’s better to have them in enterScene, I wonder what might be its benefit.

Naomi [import]uid: 67217 topic_id: 33431 reply_id: 132851[/import]

All my stuff is in enterScene, it was in CreateScene but I moved it and now I can’t remember why. I think it was because if you left the scene and went back in the particles didn’t start (or something like that).

I create the particle tables at the very top of the scene and for anything that is used in multiple scenes, I have a global particle table in main.lua. For instance I have weather effects that are through out the game, so they went into main.lua.

Dave [import]uid: 117617 topic_id: 33431 reply_id: 132901[/import]

Hello
this is how i do it

in main.lua i preload a lot of shard resources, lib_particle_candy and more

i make them global
Particles = require(‘lib_particle_candy’)
Particles.StartAutoUpdate()
then in each scen where i need the particle effect i use a custom “class”
for example particleCircle.lua
in particleCircle.lua i use the Global “Particles” object

then i use the effect like this
local pCircle = require(“particleCircle”) – if this is used a lot i make this global a swell

pCircle.run(x,y) – fire the effect

pCircle.clean() – if you want to clean up
Its clean and easy to reuse in other projects

i build each effect in a “class” file
[import]uid: 147488 topic_id: 33431 reply_id: 132911[/import]

@thedavebaxter and @blomjens1, thank you so much for sharing your experience, thoughts and methods. I really appreciate it.

I was thinking of breaking out the particle effects I’m creating to a separate module (i.e., making it a custom class) so that all I have to do is to look at the module to manipulate, change and add more to. But for now, I feel I need to become more familiar with and understand how Particle Candy works before I make that move.

About StartAutoUpdate, I didn’t quite understand what it did when I first saw it in the reference page of the x-pressive website. I looked at it again just now, and actually, it sounds really good. If I understand it correctly, rather than adding & removing the Runtime EventListener the way I did in enterScene and exitScene, all I have to do is to call StartAutoUpdate (at enterScene, in my current setup), and then simply call CleanUp in the exitScene (which would stop the StartAutoUpdate and clean up all the Particle Candy related items I created.) Very cool. [EDIT: Yeah, it did work! Yay.]

Thanks again!!

Naomi
[import]uid: 67217 topic_id: 33431 reply_id: 132943[/import]

I add this code to the main.lua an only run it once before any storybord code
Particles = require(‘lib_particle_candy’)
Particles.StartAutoUpdate()

and i set a short life time so particle candy clean up by it self
that way on don’t call the clean function at al
I also did a simple particle editor with realtime update
that way i can easy play with all the parameters and se the result right a way
the when im happy i tap a button that prints all the settings in the output
just copy paste in a file and your done :slight_smile:
Some where in the code exchange there is a particle candy editor that use to build my editor
i removed the tabs and added the preview and parameters on the same “view”

[import]uid: 147488 topic_id: 33431 reply_id: 132953[/import]

That seems to make sense to me. I always advise people that for things that belong to that scene, if you create it in enterScene() remove it in exitScene() so what you’ve done seems to make sense.

[import]uid: 199310 topic_id: 33431 reply_id: 132797[/import]

Hey, @blomjens1, thank you for your tip!

I do set certain things global (like sound files and dictionally that gets built and loaded at the app startup – so it won’t lag so much when the game starts up.) I’ll keep your advice in mind as I build more effects, and if I see that it would make more sense to make it global, I’ll do what you suggested. My current game plays inside a single scene (game.lua), and for now, I don’t show particle effects in any other module. So I don’t feel I need to use globals (especially since Particle Candy executes and loads super duper fast and I don’t need to re-use it in any other scene.)

About applying the short life time, good to know. About particle editor thingy, it sounds terrific.

Thanks again!

Naomi

[import]uid: 67217 topic_id: 33431 reply_id: 132962[/import]

Thank you for the feedback, Rob. I appreciate it.

In the storyboard sample code that comes with Particle Candy, what I do in createScene is actually done in enterScene, and I’m wondering if I should move all Particle Candy related code that I currently have in createScene to enterScene. Is it all about personal preference or is there a good reason why I should. And if it’s better to have them in enterScene, I wonder what might be its benefit.

Naomi [import]uid: 67217 topic_id: 33431 reply_id: 132851[/import]

All my stuff is in enterScene, it was in CreateScene but I moved it and now I can’t remember why. I think it was because if you left the scene and went back in the particles didn’t start (or something like that).

I create the particle tables at the very top of the scene and for anything that is used in multiple scenes, I have a global particle table in main.lua. For instance I have weather effects that are through out the game, so they went into main.lua.

Dave [import]uid: 117617 topic_id: 33431 reply_id: 132901[/import]

Hello
this is how i do it

in main.lua i preload a lot of shard resources, lib_particle_candy and more

i make them global
Particles = require(‘lib_particle_candy’)
Particles.StartAutoUpdate()
then in each scen where i need the particle effect i use a custom “class”
for example particleCircle.lua
in particleCircle.lua i use the Global “Particles” object

then i use the effect like this
local pCircle = require(“particleCircle”) – if this is used a lot i make this global a swell

pCircle.run(x,y) – fire the effect

pCircle.clean() – if you want to clean up
Its clean and easy to reuse in other projects

i build each effect in a “class” file
[import]uid: 147488 topic_id: 33431 reply_id: 132911[/import]

@thedavebaxter and @blomjens1, thank you so much for sharing your experience, thoughts and methods. I really appreciate it.

I was thinking of breaking out the particle effects I’m creating to a separate module (i.e., making it a custom class) so that all I have to do is to look at the module to manipulate, change and add more to. But for now, I feel I need to become more familiar with and understand how Particle Candy works before I make that move.

About StartAutoUpdate, I didn’t quite understand what it did when I first saw it in the reference page of the x-pressive website. I looked at it again just now, and actually, it sounds really good. If I understand it correctly, rather than adding & removing the Runtime EventListener the way I did in enterScene and exitScene, all I have to do is to call StartAutoUpdate (at enterScene, in my current setup), and then simply call CleanUp in the exitScene (which would stop the StartAutoUpdate and clean up all the Particle Candy related items I created.) Very cool. [EDIT: Yeah, it did work! Yay.]

Thanks again!!

Naomi
[import]uid: 67217 topic_id: 33431 reply_id: 132943[/import]

I add this code to the main.lua an only run it once before any storybord code
Particles = require(‘lib_particle_candy’)
Particles.StartAutoUpdate()

and i set a short life time so particle candy clean up by it self
that way on don’t call the clean function at al
I also did a simple particle editor with realtime update
that way i can easy play with all the parameters and se the result right a way
the when im happy i tap a button that prints all the settings in the output
just copy paste in a file and your done :slight_smile:
Some where in the code exchange there is a particle candy editor that use to build my editor
i removed the tabs and added the preview and parameters on the same “view”

[import]uid: 147488 topic_id: 33431 reply_id: 132953[/import]

Hey, @blomjens1, thank you for your tip!

I do set certain things global (like sound files and dictionally that gets built and loaded at the app startup – so it won’t lag so much when the game starts up.) I’ll keep your advice in mind as I build more effects, and if I see that it would make more sense to make it global, I’ll do what you suggested. My current game plays inside a single scene (game.lua), and for now, I don’t show particle effects in any other module. So I don’t feel I need to use globals (especially since Particle Candy executes and loads super duper fast and I don’t need to re-use it in any other scene.)

About applying the short life time, good to know. About particle editor thingy, it sounds terrific.

Thanks again!

Naomi

[import]uid: 67217 topic_id: 33431 reply_id: 132962[/import]

@Naomi -you can do both, generate your particle types once at start or each time when your app enters a scene, level etc. Just keep in mind that you will have to create your particle types again once they have been destroyed using Particles.CleanUp() -wherever you use it.

Note, by the way, that ClearParticles() does not destroy any emitters or particle types (like Particles.CleanUp does), it just clears the screen from any particles.

Also note that you should destroy your emitters properly (using Particles.DeleteEmitter) before an emitter is deleted automatically by Storyboard or by deleting any parent object where your emitters are nested in, otherwise there could remain associated data in memory.

[import]uid: 10504 topic_id: 33431 reply_id: 133466[/import]

Thank you, @x-pressive. I appreciate you mentioning ClearParticles(). I now feel I have a very good handle over how I may use Particle Candy. It’s super well put-together & awesome library.

Naomi [import]uid: 67217 topic_id: 33431 reply_id: 133511[/import]

@Naomi -you can do both, generate your particle types once at start or each time when your app enters a scene, level etc. Just keep in mind that you will have to create your particle types again once they have been destroyed using Particles.CleanUp() -wherever you use it.

Note, by the way, that ClearParticles() does not destroy any emitters or particle types (like Particles.CleanUp does), it just clears the screen from any particles.

Also note that you should destroy your emitters properly (using Particles.DeleteEmitter) before an emitter is deleted automatically by Storyboard or by deleting any parent object where your emitters are nested in, otherwise there could remain associated data in memory.

[import]uid: 10504 topic_id: 33431 reply_id: 133466[/import]

Thank you, @x-pressive. I appreciate you mentioning ClearParticles(). I now feel I have a very good handle over how I may use Particle Candy. It’s super well put-together & awesome library.

Naomi [import]uid: 67217 topic_id: 33431 reply_id: 133511[/import]