The basics

Hi there,

Bought Particle Candy and am having troubles getting it going quickly.

I started off having a browse through some of the amazing effects and then looked through some of the lua files and looked daunting so I thought I’d start off slow and complete the Quickstart (http://www.x-pressive.com/ParticleCandy_Corona/howto.html).

The Quick Start used a lot of new words which I can learn but after copying and pasting the Quick Start code into a new document I thought this would make something happen and then go from there but I assume the Quick Start example is just an abstract of key bits to make an effect.

Could someone point me to either a simple tutorial or the appropriate sample in the folder of local particle candy examples to start off and understand whats going on?

I could spend more time learning whats going on myself but since using Corona and Lua everything has been very understandable and relatively simple but since last night Particle candy has had me stumped.

Hope someone can de-misify things… [import]uid: 33866 topic_id: 6539 reply_id: 306539[/import]

It’s really quite simple:

1.) INCLUDE THE LIBRARY TO YOUR CODE
[lua]ParticleLib = require(“lib_particle_candy”)[/lua]
Put this on top of your code to include the library (a copy of the library file should be placed inside your project’s folder, where your main.lua resides, to avoid path problems). You can change the name “ParticleLib” to any phrase you like. Think of it as a variable that now contains the complete particle library.

2.) CREATE YOUR PARTICLE TYPES
Now create one or more particle types. A particle type describes how particles of this type will behave once they are emitted. Here is a very simple one, for example:
[lua]ParticleLib.CreateParticleType (“MyFirstParticleType”,
{
imagePath = “arrow.png”,
imageWidth = 32,
imageHeight = 32,
velocityStart = 150,
lifeTime = 4000,
} )[/lua]
3.) CREATE AN EMITTER
Then you can create one or more emitters. By default, each emitter is “empty”, you have to “load” it with one or more particle types. So simply attach the particle type you created to it, together with some parameters like emission rate, emission duration etc. (as described in the manual):

[lua]-- CREATE AN EMITTER AT X=50, Y=100
ParticleLib.CreateEmitter(“MyEmitter”, 50,100, 45, true, true)
– ATTACH YOUR PARTICLE TYPE TO IT:
ParticleLib.AttachParticleType(“MyEmitter”, “MyFirstParticleType”, 10, 9999,0) [/lua]
4.) TRIGGER THE EMITTER
You can now trigger the emitter (let it emit particles) at any time:
[lua]ParticleLib.StartEmitter(“MyEmitter”)[/lua]
Don’t forget to call ParticleLib.Update() frequently (or ParticleLib.StartAutoUpdate() once) since this will update all your particles frame by frame.

That’s basically all and you’ll find that each sample is structured like this. Include the library, define some particle types, create your emitters, feed and trigger them.

If you still got any questions, just let me know.

Regards,
Mike
[import]uid: 10504 topic_id: 6539 reply_id: 22674[/import]

Particle candy is indeed very simple to use.

I have learn by using the demo codes, and starting to tune them.

There are indeed a lot of new words, but within a coule of days, you will be astonished, saying “that’s all ! that’s all I need to know ?!”.

I do de-mistify :

  • sample codes are clever
  • and particles concept (the 1 to 4 steps explained above) is brillant :slight_smile:

Enjoy ! [import]uid: 9328 topic_id: 6539 reply_id: 22750[/import]

Ahhh… nice one, got it working! Now I can start to dissect all the sample code!

Can’t wait :slight_smile:

Thanks for the help!

[import]uid: 33866 topic_id: 6539 reply_id: 22795[/import]

Hmmmmmmm I just started to play around with this and it blackouts the game and gives me a syntax error.

This is right under my require physics

 ParticleLib = require("lib\_particle\_candy") 

Then this later on in the code,

[code] ParticleLib.CreateParticleType (“Particle1”,
{
imagePath = “spark.png”,
imageWidth = 32,
imageHeight = 32,
velocityStart = 150,
lifeTime = 4000,
} )

[/code]

Then,

 ParticleLib.CreateEmitter("Emitter1", 50,100, 45, true, true) 

Then,

ParticleLib.AttachParticleType("Emitter1","Particle1", 10, 9999,0) 

And finally,

 ParticleLib.StartEmitter("Emitter1")

I have a feeling the thing im doing wrong is a no-brainer to fix…

Oh and Ive made sure I have the lib_particle_candy loaded in my game file…
[import]uid: 10355 topic_id: 6539 reply_id: 23364[/import]

Opps I fixed the Syntax error. XD But it still doesnt work… [import]uid: 10355 topic_id: 6539 reply_id: 23368[/import]

Are you sure that you also call Particles.Update() once per frame (or called Particles.StartAutoUpdate() once)?

Could you post your entire code?

The best way is to start with one of the included samples. Just try them out, change the particle type’s parameters to see the results, add some emitters or particle types etc. and you should get familiar with it very quickly. [import]uid: 10504 topic_id: 6539 reply_id: 23385[/import]

Awesome, calling the update did the trick! Thanks you! [import]uid: 10355 topic_id: 6539 reply_id: 23493[/import]

Is there anyway to attach an emitter to a physics body? [import]uid: 10355 topic_id: 6539 reply_id: 23531[/import]

Try using the SetEmitterTarget() command. This will let the emitter automatically follow another object. [import]uid: 10504 topic_id: 6539 reply_id: 23605[/import]

I basically just have, SetEmitterTarget(“E1”, “star”, true, 0)

But its not working… is there anything more to it than that? [import]uid: 10355 topic_id: 6539 reply_id: 23914[/import]

You used a string as the second parameter (note the quotes: " star " ), but this should be a handle (reference) to a display object instead:

[lua]MyImage = display.newImage(“spaceship.png”)
Particles.SetEmitterTarget(“E1”, MyImage, true, 0)[/lua]

[import]uid: 10504 topic_id: 6539 reply_id: 24023[/import]

Ahh perfect, works like a charm! Now one last question ( sorry for asking so many), but is there a way to attach the StartEmitter command to an event? such as a touch or collision.

[import]uid: 10355 topic_id: 6539 reply_id: 24095[/import]

Sure, just place the command within your listener function, for example. [import]uid: 10504 topic_id: 6539 reply_id: 24168[/import]

I wonder if “images.png” are mandatory and the only way to create particules or if it’s possible to use “texts” or “circles”, etc.(cf. display.newText, display.newCircle, etc.)
If yes, please point me a direction to adapt the code/library.
Thanks. [import]uid: 8970 topic_id: 6539 reply_id: 25892[/import]

You can do so by editing a certain line. Search for the line that begins with

[lua]Particles[slot] = display.newImageRect[/lua]

and change it to your needs. The performance of texts, however, would probably be quite slow compared to images. [import]uid: 10504 topic_id: 6539 reply_id: 25902[/import]

I continue exploration of particulesCandy and it’s really amazing!

a) I’d like particules don’t go outside a circleFXfield (the emitter is inside the circle); does’nt work; do I miss something?

b) I would like to emit “text” instead of images. For that I use a “Properties.text” and have amended library for that like you said (#15). It works.
I would like now that the text is amended each time a value is amended (for eg. suppose the changing value is a score)
I try something like that
[lua]local function updTxt()
Properties.Text = “”…tostring( score )…""
end
Runtime:addEventListener(“enterframe”, updTxt)[/lua]
But, crash… How to do that?. Thanks in advance. [import]uid: 8970 topic_id: 6539 reply_id: 26444[/import]

To emit any texts or characters:

At line 920, find:

[lua]if PType.SpriteSet == nil then
Particles[slot] = display.newImageRect(PType.imagePath,PType.imageWidth,PType.imageHeight)
Particles[slot].xReference = PType.xReference
Particles[slot].yReference = PType.yReference
else[/lua]

replace with:
[lua]if PType.text ~= nil then
Particles[slot] = display.newText( PType.text, Emitter.x, Emitter.y, native.systemFont, 25 )
elseif PType.SpriteSet == nil then
Particles[slot] = display.newImageRect(PType.imagePath,PType.imageWidth,PType.imageHeight)
Particles[slot].xReference = PType.xReference
Particles[slot].yReference = PType.yReference[/lua]
Then just add this line to your particle type definition, that’s basically it =)

[lua]Properties.text =“Boo!”[/lua]
If you attach a listener to it, you’ll also have to remove it again, otherwise the particles will not be removed from memory. Objects aren’t garbage collected if there is still a listener attached to it. [import]uid: 10504 topic_id: 6539 reply_id: 26464[/import]

Thanks a lot. Very grateful for your support. In fact emitting text was already ok. My problem is to update this text. You said “If you attach a listener to it, you’ll also have to remove it again”, not quite sure to implement it correctly.

[lua]local Particles = require(“lib_particle_candy”)

t1 = system.getTimer()

–to display seconds
local function running(event)
t2 = system.getTimer()
ms = t2 - t1
t1 = t1
floor = math.floor
sec = floor(ms/1000); --I try to display “sec value” in Propertie.text
end
timer1 = timer.performWithDelay(1, running, 0)

local Properties = {}
Particles.CreateEmitter(“E1”, 30, 240, 0, true, true)
Properties.text = “”…tostring( sec )…""
Properties.velocityStart = 200
Properties.alphaStart = 0
Properties.fadeInSpeed = 1.0
Properties.fadeOutSpeed = -1.0
Properties.fadeOutDelay = 5000
Properties.scaleStart = 1.0
Properties.weight = 0.2
Properties.bounceX = true
Properties.bounceY = true
Properties.bounciness = 0.8
Properties.emissionShape = 0
Properties.emissionRadius = 100
Properties.killOutsideScreen = true
Properties.lifeTime = 6000
Properties.autoOrientation = true

Particles.CreateParticleType (“Test”, Properties)
Particles.AttachParticleType(“E1”, “Test”, 10, 3000,2000)
Particles.StartEmitter(“E1”)
local Emitter = Particles.GetEmitter(“E1”)
Emitter.rotation = 45
local function main()
Properties.text = “”…tostring( sec )…"" --not updated (nil appears screen simulator)
Particles.Update()
end
Runtime:addEventListener( “enterFrame”, main )[/lua]

[import]uid: 8970 topic_id: 6539 reply_id: 26581[/import]

If I understand correctly, you would like to display the seconds using particles.

If so, there is no need to use an event listener. You can use a timer that ticks once per second to update the text. Here is a working sample:

[lua]-- LOAD PARTICLE LIB
local Particles = require("…/lib_particle_candy")

local screenW = display.contentWidth
local screenH = display.contentHeight

– CREATE AN EMITTER
Particles.CreateEmitter(“E1”, screenW*0.1, screenH*0.8, 90, true, true)

– DEFINE PARTICLE TYPE PROPERTIES
Particles.CreateParticleType (“Test1”,
{
velocityStart = 150,
useEmitterRotation = false,
killOutsideScreen = true,
lifeTime = 3000,

text = “1”,
})

– FEED EMITTER
Particles.AttachParticleType(“E1”, “Test1”, 5, 99999,0)

– TRIGGER EMITTER
Particles.StartEmitter(“E1”)

– UPDATE PARTICLES
Particles.StartAutoUpdate()

– UPDATE PARTICLES’ TEXT ONCE PER SECOND
local startTime = system.getTimer()

function updateTime(event)
local seconds = math.ceil((system.getTimer() - startTime) / 1000)
Particles.SetParticleProperty(“Test1”, “text”, seconds )
end
timer.performWithDelay( 1000, updateTime, 0 )[/lua] [import]uid: 10504 topic_id: 6539 reply_id: 26587[/import]