Search code examples
iphoneobjective-canimationparticles

Simulating a candle flame in Objective C


As part of a current project I've been asked to display a candle onscreen. Users should be able to tilt the device to tilt the flame, and perform an action (eg. tap) to blow out the flame. I'm at a real loss on how to achieve this. Some ideas I've had:

  • purchase a movie of a candle from a stock video site. This won't let me tilt or blow out the flame though
  • obtain a number of frames and animate them to give the appearance of a flickering flame
  • use some form of particle emitter

I guess my preference would probably be to use the particle emitter, as I can't see the video working and getting the necessary assets for the frame animation could be a problem. I know Cocos2D has a particle emitter, but this is part of a larger UIKit project which can't be ripped apart and started again to build on top of Cocos2D.

Does anyone have any ideas on how I can achieve this?


Solution

  • You could look at the Nehe tutorial on particle generation:

    http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=19

    It wouldn't be hard to adapt this to produce something that looks like a candle.

    (You can embed a GL view inside another view for this.)