Discussion for Tutorial 8 - Particle Emitter

Discussions for all the iPhone Screencast Tutorials.

Discussion for Tutorial 8 - Particle Emitter

Postby jonny » Sun Aug 23, 2009 3:17 am

Finally I’ve managed to finish the Particle Emitter tutorial. I got seriously side tracked with other fun things like sound etc on the iPhone, but I’ve managed to focus back on this and get it finished.

This tutorial will go through the creation of a particle emitter. This is a class which can generate a large number of objects, particles, on screen and control them in an organic way. This is normally used to generate effects such as fire, smoke, sparks etc.
jonny
Site Admin
 
Posts: 11
Joined: Wed Apr 22, 2009 4:50 am

Re: Discussion for Tutorial 8 - Particle Emitter

Postby Elphaba » Tue Aug 25, 2009 6:23 pm

I see again that you've used code from the 'Cocos2D' engine in this.

Whilst your particle system is really cool and has a nice 'init' method that allows lots of fiddling and tweaking, I'm more interested in why you/they went with POINTSPRITES rather than the PVR / Apple preferred technique of interleaved Vertex Arrays?

I've been trying to dig up some empirical evidence about which - for the same system / size / number etc... is the most efficient, however, all evidence so far, in lieu of an actual proper test, is that Interleaved Vertex Arrays with shorts (not floats) and the colors specified as an INT are MUCH more efficient and fast - as the hardware doesn't have to do any transformations or data conversions on the fly.

Any thoughts on this?
Elphaba
 
Posts: 6
Joined: Sun Aug 23, 2009 3:15 pm

Re: Discussion for Tutorial 8 - Particle Emitter

Postby mike » Wed Aug 26, 2009 12:22 pm

Hi Elphaba

Your right, Cocos2D was a big influence on my design for the particle system. For the effects I was looking for I didn't need to have different textures inside a particle emitter. Going forward I'm sure that will be an enhancement I will make. I also wanted to keep things simple as the tutorials were for beginners and I was learning at the same time ;)

Apart from have a 64px limit and the texture needing to be square, point sprites have worked really well. As I developed the particle system I was originally using my own textures and switching to point sprites did make a significant improvement on performance. That said, I had not optimized the non point sprite approach as you have mentioned, so the speed increase may have been less if at all using that approach.

Having brought this up, I'd be interested to try a version of the particle system that uses the PVR/IVA approach and see what the performance is like. The particle system is very much stand alone at the moment with its own rendering code etc, so changing it should not be too hard. I'd need to find some time as the book is using all my spare capacity at the moment :) but I think it would be an interesting exercise for the book as well.

If you have any other info or comments on this topic I'd be very interested to hear them :)

Mike
mike
 
Posts: 670
Joined: Fri Aug 21, 2009 2:10 pm

Re: Discussion for Tutorial 8 - Particle Emitter

Postby cyoung_mi » Thu Sep 03, 2009 6:20 am

Mike,
Thank you for all your hard work! Really looking forward to the book!

I have one question, I can't seem to figure out.
I'd like to add one more method to the Particle Emitter.

I'd like to add initParticleEmitterWithImageNamedAtTileLocation:

So it matches the player and enemy functions, I would like to pass the Particle Emitter
to a Tile Location instead of just screen location.

I thought it should be pretty easy, but I'm having a hard time.
Any help or thoughts?
Thanks!
Chris
cyoung_mi
 
Posts: 10
Joined: Thu Sep 03, 2009 6:15 am

Re: Discussion for Tutorial 8 - Particle Emitter

Postby mike » Thu Sep 03, 2009 8:23 am

Hi cyoung_mi

That's a cool idea. From what you have said you would like to use the image at a tile location as the texture within a particle effect?

Let me have a little think about that and I'll come back to you shortly :ugeek:

Mike
mike
 
Posts: 670
Joined: Fri Aug 21, 2009 2:10 pm

Re: Discussion for Tutorial 8 - Particle Emitter

Postby cyoung_mi » Fri Sep 04, 2009 2:45 am

Mike,
Actually that's a cool idea too! but that's not what I was looking for.

I was looking for a way to render a Particle Emitter at a Tile Location, like we do
with the player icon, and ghost icons..

If I understand it correctly, you Init the Particle emitter at screen location ( 160,240 )
and the Player and ghost inits you pass in a tile x,y location ( player.x=2 player.y=5 )

I would like a way to init a Particle emitter in the same way.. so I can create a flame
or water effect, and instead of needing to figure out the screen x,y.. I can just
place it on top of a tile location.

But I can't seem to wrap my head around it..
Thanks
cyoung_mi
 
Posts: 10
Joined: Thu Sep 03, 2009 6:15 am

Re: Discussion for Tutorial 8 - Particle Emitter

Postby mike » Fri Sep 04, 2009 6:09 pm

Ah right, sorry, I see what you mean now.

The easiest way to do that without any changes to the particle emitter would be to multiply the tile x and y location by the tile width and height. The result is the pixel location for the particle emitter.

For example, if you wanted to place a particle emitter in the middle of the tile at 12, 13 you would do the following
Code: Select all
x = 12.5 * tileWidth;
y = 13.5 * tileHeight;


You can then pass x and y to the particle emitter and it will render at the correct pixel location.

Let me know if this helps or not.

Mike
mike
 
Posts: 670
Joined: Fri Aug 21, 2009 2:10 pm

Re: Discussion for Tutorial 8 - Particle Emitter

Postby Sumaleth » Mon Nov 23, 2009 6:17 am

In this Particle class (in the tutorial video at least), you set color randomization like this:

Code: Select all
Color4f start = {0, 0, 0, 0};
start.red = startColor.red + startColorVariance.red * RANDOM_MINUS_1_TO_1();
etc...


So if the random number comes back as -0.5, for example, and the startColorVariance.red is 0.1, then the red color will be:

Code: Select all
start.red = 0 + (0.1 * -0.5) = -0.05;


ie, a minus value for the red contribution, or indeed any of the start/end colors.

It does actually work in your tutorials, so presumably the value is clipped to 0 or abs()'d, but unless I'm misreading I think RANDOM_0_TO_1() would be better suited.

I do like the particles though. Possibilities, possibilities. :)
Sumaleth
 
Posts: 197
Joined: Thu Sep 03, 2009 9:55 am

Re: Discussion for Tutorial 8 - Particle Emitter

Postby mike » Mon Nov 23, 2009 1:45 pm

Your right about the values being only valid between 0 and 1. I'm using -1 to 1 so that the variance can be both above and below the value of the colour.

i.e if the color is 0.75 with a variance of 0.2, I want that to be a positive or negative variance e.g.

color = 0.75
variance = 0.2
random number = -0.5
result = 0.65

color = 0.75
variance = 0.2
random number = 0.5
result = 0.85

This means the variance value can be both positive and negative. If it goes above 1 or below zero its just capped.

Mike
mike
 
Posts: 670
Joined: Fri Aug 21, 2009 2:10 pm

Re: Discussion for Tutorial 8 - Particle Emitter

Postby Sumaleth » Mon Nov 23, 2009 2:01 pm

Ah, makes sense.
Sumaleth
 
Posts: 197
Joined: Thu Sep 03, 2009 9:55 am

Next

Return to iPhone Game Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest

cron