O'Reilly logo

Cocos2d Cross-Platform Game Development Cookbook - Second Edition by Siddharth Shekar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding the glass effect

We will look at some of the more complex effects.

Getting ready

To add a glass effect, first of all, we need to add the glass image and then a normal map of the glass image to the project.

How to do it…

First, we will add the glass sprite to the scene, as follows:

//crystal sprite

CCSprite* crystal = [CCSprite spriteWithImageNamed:@"granite_DIF.png"];

crystal.position = CGPointMake(winSize.width/2, winSize.height/2);

[self addChild:crystal];

crystal.normalMapSpriteFrame = [CCSpriteFrame frameWithImageNamed:@"granite_NRM.jpg"];

Now that the glass sprite is added in, we can create the effect. We will execute the following code for this:

 //** Glass effect CCEffectGlass* glassEffect = [CCEffectGlass effectWithShininess:1.0f refraction:1.0f ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required