Sunday, October 16, 2011

Cocos2d CCSprite Reflection

With yet another 2 months of Wild West Development behind me, I can hopefully get back to a somewhat normal life again, blogging, learning and a little iOS game development.

What I want to share today is my little hack to reflect a CCSprite used in to cocos2d. I say hack because it does feel a little dirty, i didn't go and learn about the details of Open GL and the like, simply patched things together to get a working solution.

Below is the code for my ImageReflector, the basic idea and how it got it work was simple:

The best looking reflection example I found was Apples' example. So the methods createBitmapContext, createGradientImage and reflectedImage are directly from the above example. I wanted to use it in cocos2d so I used CCRenderTexture to create a UIImage, passed that to Apples' example code and then simply converted back to a CCSprite with the help of the CCTexture2D class.

Usage: Class:

Popular Posts

Followers