Beginner que

Hi,

First of all, thanks for this lovely package. For the sake of learning, I tried to make a effect from scratch with this code but it yields runtime error on physics.addBody in Particle Helper. Here is my main.lua file:

local CBE = require("CBEffects.Library") local mrand=math.random local function buildSparks() local size=mrand(10,20) -- return display.newImageRect("star.png", size, size) return display.newImageRect("star.png", 10, 10) end local function velNil() return 0, 0 end local kos = CBE.VentGroup { { title="stars", isActive=true, build= buildSparks, x=display.contentCenterX, y=display.contentCenterY, color={{255,255,255},{230,230,255}}, iterateColor=false, curColor=1, emitDelay=1000, perEmit=6, emissionNum=0, lifeSpan=1000, alpha=1, startAlpha=0, endAlpha=0, onCreation=function() end, onDeath= function(p,v) v.perEmit=math.random(5,15) end, propertyTable={}, scale=1.0, lifeStart=0, fadeInTime=300, iteratePoint=false, curPoint=1, lineDensity="total", pointList={{0,0},{1,1}}, positionType="inRadius", posRadius=30, posInner=1, point1={100,display.contentHeight}, point2={display.contentWidth-100,display.contentHeight}, rectLeft=0, rectTop=0, rectWidth=display.contentWidth, rectHeight=display.contentHeight, onUpdate=function() end, physics={xDamping=0,yDamping=0,density=1,velocity=5,angularVelocity=0.04,angularDamping=0,velFunction=velNil,useFunction=false,autoAngle=true,angles={{0,360}},preCalculate=true,sizeX=0,sizeY=0,minX=0.1,minY=0.1,maxX=100,maxY=100,relativeToSize=true,gravityX=0,gravityY=9.8}, rotation={towardVel=false,offset=0} } } --kos:start("stars") kos:startMaster()

I basically copied one of the presets and wanted to compile and run then try to change values to get what I want but it won’t run.

Thanks.

Do you have the most recent version of CBEffects? (Two and Four-Ninths, I believe) My version (most recent) is having some hiccups even when I got your code to working - I’m thinking it’s an out-dated preset (especially after I see xDamping and yDamping both set to 0 - you can’t do that with the more recent versions with the default configuration. It’ll attempt to divide the velocity by 0 and return infinity, so it’ll appear like particles are invisible). If you get the most recent version, and use the preset from it, your parameters should work.

That’s not the problem, though - when I run your code, it’s saying that the image “star.png” doesn’t exist. That’s making the particle turn into nil, and thus when ParticlePhysics attempts to add “body” to it, it’s finding nothing to add body to, and is throwing an error. I replaced it with an image I knew existed and it worked perfectly.

Let me know how it turns out :slight_smile:

Caleb

Hey man, thanks for the reply.

I got the it from
http://www.gymbyl.com/ which i believe is your site and should have
latest version. Then I copied spark to my main.lua file and here is the
rest.

I put the star.png file in root of my project, is this the correct place for it? It was there the whole time but it was not saying that it misses that file.

BTW, am I using CBEffect the right way? I just need to call CBE.VentGroup and make my particle?

Not
to be ungrateful or something but wish you had a beginner tutorial or
something. I read your PDF but I think it needs a beginner section.

Thanks again for such great package!

BTW,
does any of your packages have bitmap font support? I saw a string with
alphabet in one of your source codes but have no idea if I cna do the
same with it. It would be great if I could write something with a bitmap
font and then it would fade away and things like that, for things like
combo counters and whatnot.

Not sure what’s happening with your main problem - when I run your code, I get

[lua]

WARNING: Failed to find image(star.png)

2013-05-29 13:29:19.472 Corona Simulator[11628:1c03] Runtime error

…e/Desktop/Games/CBEffectsTestErrors/CBEffects/ParticleHelper.lua:288: attempt to index local ‘obj’ (a nil value)

stack traceback:

    [C]: ?

    …e/Desktop/Games/CBEffectsTestErrors/CBEffects/ParticleHelper.lua:288: in function ‘addBody’

    …lebplace/Desktop/Games/CBEffectsTestErrors/CBEffects/Library.lua:189: in function ‘_listener’

    ?: in function <?:141>

    ?: in function <?:218>

[/lua]

which of course would make sense - I don’t have the star.png file. But when I replace it with an existent image, it works perfectly. So if star.png is existent, it should work. All I can say is that it might have an incorrect name or something like that.

As for using it correctly, that’s right. I went for a different approach with CBEffects than with “normal” particle systems - you’re doing it correctly.

As for a beginner section, there aren’t many tutorials currently (a problem that I’m working on), but here the current list of them are:

Create a Rain Effect (pretty good for beginners): http://forums.coronalabs.com/topic/33869-tutorial-create-a-rain-effect/

CBResources (a moderately large sample set): http://www.gymbyl.com/programming/cbresources.html

Simple CBEffects Sample (may not work - it’s pretty old): http://bit.ly/ZbXBU5

And, as for the CBEffects version, if you got it recently from my site, then it’ll be the most recent :slight_smile:

I have not (as yet) created a bitmap font library; I may try in the future. However, CBText is a library (currently unpublished and on hold) that should be able to do some pretty cool effects, even though it uses normal fonts - not sure if it’ll be perfect, but it should be quite cool :slight_smile:

Caleb

Thanks man, you were right, I put my star.png in CBeffects’s folder but then I moved it to root of my project and it went fine about that error but I can’t see anything when I run this. What now?

BTW, you mentioned these samples are out of date, are they safe to use as reference for making my own particles? Because you mentioned there are some obsolete properties there.

Thanks.

All of the samples aren’t out of date - just the third one. In CBResources, only the samples in the “OldSamples” folder are out of date - I just included them in case someone wanted to use them anyway. Everything else should work.

You’re not seeing anything because of a mixture of your xDamping and yDamping values, and because of your gravity setting. In older versions of CBEffects, the ParticlePhysics values were a lot lower than the newer versions. Thus, a setting of, say, 0.1 for gravity might be the same as a setting of 10 for an older version (due to relativeToSize+density - both weird-acting, problem parameters. They’re getting removed with the next version, Two and One-Half). When gravity is up to 9.8, particles will have an immense speed growing power downwards. You might try lowering the gravity.

But, that’s really not the bigger problem. Your x- and y-damping are both 0, and with more recent versions, particle damping is applied by division. When it divides a number by 0 (not valid, of course), it returns infinity. Thus, particles are attempting to move infinitely, which makes them invisible.

You might also try, to clean up your code, simply putting “preset=“sparks”” in the data table - that does the same thing as copying and pasting, but it’s a lot cleaner :slight_smile: All values can be changed simply by adding them in there and they’ll overwrite the preset’s values.

[lua]

local kos=CBE.VentGroup{

    {

        preset=“sparks”,

        build=function() – Overwrites the sparks build function

            return display.newImageRect(“star.png”, 10, 10)

        end

    }

}

[/lua]

Caleb

Thanks Caleb,

I copied the preset into my project to learn different aspects of a particle that I can change.

The problem was indeed the damping ones, I changed them to 1 and I can see particles now! Some things though:

  1. I checked other presets in ParticleHelper.lua and I see other xDamping and yDamping set to zero, are they not out of date?

  2. I changed my code to your sample code that you posted in previous post and it works but why? Isn’t it copying the “sparks” preset into my Vent and then override what I change about it? If yes, then the preset has the old damping values of zero but I can see particles now, why is that? Don’t I have to change damping values to make it work?!

  3. Do I have to manually remove particles from the screen after they “die”, i.e. faded away or something like it ? Because after a few seconds my empty project with just a particle emitter gets slower.

Thanks again for this great package. I have extended experience as particle designer previously and I like your new approach to particles.

Best,

  1. If you see xDamping and yDamping as 0 in other samples, that simply means that the version of CBEffects they are using (perhaps even the most recent one) defaults to subtraction damping. If subtraction damping is active, damping will be subtracted from the velocity, so a value of 0 means no damping. This is different with division damping, though - a value of 1 means no damping, because anything divided by 1 equals itself.

  2. That should explain this question, too - subtraction damping is active, apparently.

  3. You do not; they should be removed automatically. Can you please elaborate on what’s happening, though? If it’s really slowing down consistently, there might be a memory leak… :frowning:

Glad you like the package!

C

Thanks for the replies,

  1. I understand some of your points but can different presets use different versions of CBEffects?!

  2. I still don’t get it would you please explain why is it that if I just call the sparks preset, it works but if I copy and paste it in my code, it won’t and I have to set 1 to x and y dampings.

  3. Slowdown occurs if I constantly emit that star.png file, framerate slows down after 2-3 seconds. Maybe due to config of the particle that need to die faster.

Thanks man!

  1. Yes, different presets can use different versions. This is because with version X, there might be a subtle change to the way that particles do such-and-such from version Y. Generally the changes are minimal.

  2. Unfortunately, I myself am not sure why this happens. If you copy and paste the sparks preset from the library, it should be exactly the same as loading it with preset=“sparks”.

  3. Does it slow down consistently? As in fast-fast-fast-fast-slower-slower-slower-slower-slower-slower-slower-slower-slower-slower? Or just fast-fast-fast-fast-slower-slower-steady-steady-steady?

C

Do you have the most recent version of CBEffects? (Two and Four-Ninths, I believe) My version (most recent) is having some hiccups even when I got your code to working - I’m thinking it’s an out-dated preset (especially after I see xDamping and yDamping both set to 0 - you can’t do that with the more recent versions with the default configuration. It’ll attempt to divide the velocity by 0 and return infinity, so it’ll appear like particles are invisible). If you get the most recent version, and use the preset from it, your parameters should work.

That’s not the problem, though - when I run your code, it’s saying that the image “star.png” doesn’t exist. That’s making the particle turn into nil, and thus when ParticlePhysics attempts to add “body” to it, it’s finding nothing to add body to, and is throwing an error. I replaced it with an image I knew existed and it worked perfectly.

Let me know how it turns out :slight_smile:

Caleb

Hey man, thanks for the reply.

I got the it from
http://www.gymbyl.com/ which i believe is your site and should have
latest version. Then I copied spark to my main.lua file and here is the
rest.

I put the star.png file in root of my project, is this the correct place for it? It was there the whole time but it was not saying that it misses that file.

BTW, am I using CBEffect the right way? I just need to call CBE.VentGroup and make my particle?

Not
to be ungrateful or something but wish you had a beginner tutorial or
something. I read your PDF but I think it needs a beginner section.

Thanks again for such great package!

BTW,
does any of your packages have bitmap font support? I saw a string with
alphabet in one of your source codes but have no idea if I cna do the
same with it. It would be great if I could write something with a bitmap
font and then it would fade away and things like that, for things like
combo counters and whatnot.

Not sure what’s happening with your main problem - when I run your code, I get

[lua]

WARNING: Failed to find image(star.png)

2013-05-29 13:29:19.472 Corona Simulator[11628:1c03] Runtime error

…e/Desktop/Games/CBEffectsTestErrors/CBEffects/ParticleHelper.lua:288: attempt to index local ‘obj’ (a nil value)

stack traceback:

    [C]: ?

    …e/Desktop/Games/CBEffectsTestErrors/CBEffects/ParticleHelper.lua:288: in function ‘addBody’

    …lebplace/Desktop/Games/CBEffectsTestErrors/CBEffects/Library.lua:189: in function ‘_listener’

    ?: in function <?:141>

    ?: in function <?:218>

[/lua]

which of course would make sense - I don’t have the star.png file. But when I replace it with an existent image, it works perfectly. So if star.png is existent, it should work. All I can say is that it might have an incorrect name or something like that.

As for using it correctly, that’s right. I went for a different approach with CBEffects than with “normal” particle systems - you’re doing it correctly.

As for a beginner section, there aren’t many tutorials currently (a problem that I’m working on), but here the current list of them are:

Create a Rain Effect (pretty good for beginners): http://forums.coronalabs.com/topic/33869-tutorial-create-a-rain-effect/

CBResources (a moderately large sample set): http://www.gymbyl.com/programming/cbresources.html

Simple CBEffects Sample (may not work - it’s pretty old): http://bit.ly/ZbXBU5

And, as for the CBEffects version, if you got it recently from my site, then it’ll be the most recent :slight_smile:

I have not (as yet) created a bitmap font library; I may try in the future. However, CBText is a library (currently unpublished and on hold) that should be able to do some pretty cool effects, even though it uses normal fonts - not sure if it’ll be perfect, but it should be quite cool :slight_smile:

Caleb

Thanks man, you were right, I put my star.png in CBeffects’s folder but then I moved it to root of my project and it went fine about that error but I can’t see anything when I run this. What now?

BTW, you mentioned these samples are out of date, are they safe to use as reference for making my own particles? Because you mentioned there are some obsolete properties there.

Thanks.

All of the samples aren’t out of date - just the third one. In CBResources, only the samples in the “OldSamples” folder are out of date - I just included them in case someone wanted to use them anyway. Everything else should work.

You’re not seeing anything because of a mixture of your xDamping and yDamping values, and because of your gravity setting. In older versions of CBEffects, the ParticlePhysics values were a lot lower than the newer versions. Thus, a setting of, say, 0.1 for gravity might be the same as a setting of 10 for an older version (due to relativeToSize+density - both weird-acting, problem parameters. They’re getting removed with the next version, Two and One-Half). When gravity is up to 9.8, particles will have an immense speed growing power downwards. You might try lowering the gravity.

But, that’s really not the bigger problem. Your x- and y-damping are both 0, and with more recent versions, particle damping is applied by division. When it divides a number by 0 (not valid, of course), it returns infinity. Thus, particles are attempting to move infinitely, which makes them invisible.

You might also try, to clean up your code, simply putting “preset=“sparks”” in the data table - that does the same thing as copying and pasting, but it’s a lot cleaner :slight_smile: All values can be changed simply by adding them in there and they’ll overwrite the preset’s values.

[lua]

local kos=CBE.VentGroup{

    {

        preset=“sparks”,

        build=function() – Overwrites the sparks build function

            return display.newImageRect(“star.png”, 10, 10)

        end

    }

}

[/lua]

Caleb

Thanks Caleb,

I copied the preset into my project to learn different aspects of a particle that I can change.

The problem was indeed the damping ones, I changed them to 1 and I can see particles now! Some things though:

  1. I checked other presets in ParticleHelper.lua and I see other xDamping and yDamping set to zero, are they not out of date?

  2. I changed my code to your sample code that you posted in previous post and it works but why? Isn’t it copying the “sparks” preset into my Vent and then override what I change about it? If yes, then the preset has the old damping values of zero but I can see particles now, why is that? Don’t I have to change damping values to make it work?!

  3. Do I have to manually remove particles from the screen after they “die”, i.e. faded away or something like it ? Because after a few seconds my empty project with just a particle emitter gets slower.

Thanks again for this great package. I have extended experience as particle designer previously and I like your new approach to particles.

Best,

  1. If you see xDamping and yDamping as 0 in other samples, that simply means that the version of CBEffects they are using (perhaps even the most recent one) defaults to subtraction damping. If subtraction damping is active, damping will be subtracted from the velocity, so a value of 0 means no damping. This is different with division damping, though - a value of 1 means no damping, because anything divided by 1 equals itself.

  2. That should explain this question, too - subtraction damping is active, apparently.

  3. You do not; they should be removed automatically. Can you please elaborate on what’s happening, though? If it’s really slowing down consistently, there might be a memory leak… :frowning:

Glad you like the package!

C

Thanks for the replies,

  1. I understand some of your points but can different presets use different versions of CBEffects?!

  2. I still don’t get it would you please explain why is it that if I just call the sparks preset, it works but if I copy and paste it in my code, it won’t and I have to set 1 to x and y dampings.

  3. Slowdown occurs if I constantly emit that star.png file, framerate slows down after 2-3 seconds. Maybe due to config of the particle that need to die faster.

Thanks man!

  1. Yes, different presets can use different versions. This is because with version X, there might be a subtle change to the way that particles do such-and-such from version Y. Generally the changes are minimal.

  2. Unfortunately, I myself am not sure why this happens. If you copy and paste the sparks preset from the library, it should be exactly the same as loading it with preset=“sparks”.

  3. Does it slow down consistently? As in fast-fast-fast-fast-slower-slower-slower-slower-slower-slower-slower-slower-slower-slower? Or just fast-fast-fast-fast-slower-slower-steady-steady-steady?

C