Simulating a candle flame in Objective C

廉价感情. 提交于 2019-12-22 09:41:57

问题


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?


回答1:


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.)




回答2:


For a previous project we had a website that had to "burn" to reveal the new website underneath. This was accomplished by recording the image of a burning piece of paper and then getting someone that was good at graphic manipulation to clean up and loop the video - this was done in Flash.

What you could do is apply this technique to your candle video. Figure out the shots you need to take to simulate all the states you want to create, including tilting and blowing the flame out, and record them. Then pass this off to someone that can create the animation loops.

Obviously something like this is going to cost a bit of money, but it's going to create the best result.

Realistic flames are really hard using a graphic engine and it's going to look fake - unless you've got a large budget.




回答3:


This isn't really an Objective-C question. What you need is an introduction to writing OpenGL shaders.




回答4:


You may still be able to use a particle generator in GL and run it in a layer on top of your other interface so you won't have to rip apart your whole app. I have seen some people complain about performance mixing these methodologies, but for a simple case it should work fine.



来源:https://stackoverflow.com/questions/4019388/simulating-a-candle-flame-in-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!