Adding a Gradient to the Texture

To make the texture look even better, we have to add a gradient from top to bottom, where the texture will get darker and darker going down.

We could do this by modifying the noise image with Gimp, but we can also do it in code, which makes things more dynamic and easily modifiable.

The basic idea is we’ll draw a black rectangle on top of the texture, but it will be completely transparent up top, and opaque at the bottom. This will keep the top untouched, but gradually darken the image going down.

To do this, we’ll need to use some OpenGL commands.

Inside spriteWithColor:textureSize, add the following code right before creating the noise sprite:

 

Tagged with:

Filed under: Cocos2diPhone

Like this post? Subscribe to my RSS feed and get loads more!