2D Particle System

Flushed with how well my code is going at the moment :D I’ve decided that I’m going to have a go at a simple 2D particle system as well. I’ve always thought of these as difficult to write and never tried before, but, given that particles in games looks cool and I’m sure I’d like to use them, I’m going to give it a go.

Not sure how long it will take, but I’ll keep you up to date and of course if I get it working I’ll follow up with a tutorial :D and I’ll be doing the other tutorials on Animation and Tilemap in the meantime.

So, wish me luck ;)

Mike

Share:
  • Digg
  • del.icio.us
  • Facebook
  • MySpace
  • Reddit
  • StumbleUpon
  • Technorati
  • TwitThis
  • Design Float
  • DZone
  • email
  • Google Bookmarks
  • LinkedIn
  • Scoopeo
  • Tumblr

12 Comments

John  on April 17th, 2009

Good luck bud ;)

Jamie Hill  on April 17th, 2009

Good luck!

I came across your site a couple of days ago and have been following your 4 tutorials on iPhone game development, I’m on the 4th now.

I’d like to say thanks for a great series of tutorials so far, the documentation on OpenGL ES and such is a little thin on the ground for us mere mortals therefore your site was a breath of fresh air.

I am massively looking forward to your tile engine tutorial as I’m interested to see how you are going to handle scrolling and such. I can’t get my head around how I would move the viewport and free up the tiles outside of the viewport for a large game level, or even if I’d need to. The last tile engine I wrote was on my Amiga 1200 in (I’m guessing) 1993 using Blitz Basic, I loved that machine ;)

I’m a web developer in my day job using Ruby so leaning Objective-C is defiantly a leaning curve what with it being statically typed. It’s all good fun and reminds me of my Amiga days.

Can I be cheeky and ask when you think you will be releasing your tile engine tutorial?

Thanks again!

mike  on April 17th, 2009

Hi Jamie, thanks for the comment

I had exactly the same problems you did when I started to think about developing on the iPhone using OpenGL ES. Given how hard I found it is why I decided to use our blog to post tutorials on what I’ve found out and what I’ve tried. I’m no expert, but I would have loved these tutorials when I started at this.

The tilemap tutorial is not that far off. I’m getting the Animation one done at the moment to get the basics finished and then I’ll be doing the tilemap.

The tilemap engine has been fun and frustrating. I’ve needed to re-factor it a few times to improve performance and managed to seriously break it. Its taken me a couple of days to get it working again and back where I was before I started messing with it :) oh well

I’m hoping to get the Animation tutorial done this weekend and I’ll then try to get the tilemap one done over next weekend as long as nothing comes up :)

I am an ex Amiga 500 man myself and I loved that machine. Nothing like putting demos together in 68000 assembler, now those were the days :D

Mike

Allan  on April 17th, 2009

Hi, I recently found your nice blog… and I’m very thankful of any help I can get, to write games for the iPhone/iPod Touch :)

I never used something like OpenGL… I’m coming from C# (we learn that at school :( )… but only the basics…

Thanks for sharing your experience with us and good luck to the 2d particle sytsem :) sounds difficult…

best regards from Austria
Allan

Jamie Hill  on April 17th, 2009

Great, thanks for the update. I’ve gone on a bit of a Nostalgia trip with the Amiga thing and downloaded E-UAE. It took me a while to figure out how to get it running so if you fancy it, you’ll need the following two apps:

http://www.e-uae.de.vu (in German but is the only Universal binary I could find)

http://www.pimley.net/projects_hi-toro.html

I managed to find Kickstart 3.1 via a torrent and if you google amiga rom you should find loads of classic roms.

Firstly make sure E-UAE is in your Applications folder. Hi-Toro is an app used to generate a conf file for UEA so launch that. Here is the config I used (the rest I left as default):

* In ROM tab, select the kickstart rom you download as the ROM.
* In the RAM tab, up the chip RAM to 2MB and the Fast RAM to 1MB.
* In the CPU tab, click 68020 (this is what the 1200′s had by memory).
* In Chipset, select AGA (again, to make it like the 1200).
* In Display, make sure you enable OpenGL or it will be painfully slow.
* In Floppies, select however many .afp files you can for the given program.
* Hit OK and prepare to have a large smile on your face ;)

You may need to tweak the display setting i.e. center the display/change the windowed resolution to 640×512 for different programs. You can also save the settings (I have settings saved for each game/program).

One last thing, if you don’t have a two button mouse, hold down apple key and click for your right button and if you want full screen hold down F11 and hit ‘S’.

Have fun!

mike  on April 17th, 2009

Thanks Allan, I’m glad your finding the site useful and hope it can help you with your projects.

I am hoping the particle system does not turn out to be too hard. My investigations so far have shown that they can be extremely sophisticated but also very simple. I’m aiming for the very simple to start off with and then see how it goes from there :D

Mike

bob  on April 18th, 2009

@Mike
Good Luck, that’s a tough one. Can’t wait to see the animation and tile map stuff. It would have taken me months to do this stuff without your Help… Again Thanks A lot, I really enjoy your tutorials and I have really gained a lot of insight on openGL for the iPhone.

mike  on April 18th, 2009

Thanks bob. I’m going to start off really simple and take it from there. I wanted to generate particle style explosions and the like, so after looking around decided I’d do my own, great way to learn :D

When you break it down, its really just having an object which can spawn particles. Each particle is its own object and handles its own direction, colour, drawing etc. You pass each particle info about gravity and direction, how long it should live for etc when you create it and then keep updating particles until they die and are removed.

The interesting part will be keeping it quick. I’m going to use the vertex arrays approach to render the particles to the screen, so we will see how it goes.

I’ve started on the code now so I’m hoping to get a prototype running soon.

Mike

bob  on April 19th, 2009

@Mike,
I came up with a system where you can draw the path you want something to follow and it gives you all of the X,Y coordinates. I draw a white line on a black background using photoshop. save image as png, then ust perl Image::Magick to find the pixels that are white and print X,Y out to a file.

#!/usr/bin/perl

use Image::Magick;

$p = new Image::Magick;
$p->Read(“./test.png”);

for($x=0; $x < 320; $x++){
$data=”";
for($y=0; $y getpixel(x=>$x,y=>$y);
if($z > 0){
print “$x $y $z\n”;
}
}

}

I haven’t figured out how to do it in a Mac program yet.

mike  on April 19th, 2009

Hi bob, that is a great idea :D

I’ll have to see how I could do the same thing on the Mac. I am sure I have seen the Image::Magick package available on the Mac. I’ll hunt it down and give this a go.

The only think I’m not sure of is how you would speed up the object following the path apart from skipping some x,y entries or something….

If you have any more ideas on this let me know, I like this one :D

Mike

Dave  on April 19th, 2009

Hi Mike,

I was recently at the Global Game Jam where we were trying to crank out a game in 48hrs.

I got the basics of a particle system coded in about 10 of those hours, and as you say, it isn’t that hard, its just a case of trying to keep the speed. Once I had my head around the basic maths it kind of flowed (heh!) from there.

Good luck!

mike  on April 19th, 2009

Thanks Dave, I appreciate the encouragement :D

I’ve got a basic concept in my head now and I’ve started to code it up. I’m going for a simple prototype first which is going to be emitting textured particles which move based on some parameters and expire over time. Once that is running and I can check out the speed I’ll then add things like scaling, colour etc

Good to know you managed to get something working in 10 hours, it gives me some hope :D

Mike

Leave a Comment