SundayMonday
SundayMonday

Reputation: 19757

Changing the opacity of a CCSprite in a CCSpriteBatchNode

Can the opacity of a CCSprite in a CCSpriteBatchNode be modified?

The following doesn't seem to work:

((CCSprite *)[batchNode getChildByTag:myTag]).opacity = 0.5;

The sprite just disappears instead of showing up with modified opacity.

Upvotes: 1

Views: 5318

Answers (1)

Kreiri
Kreiri

Reputation: 7850

This is why it's a good idea to look at the types. opacity property of CCSprite is GLubyte. Looking at GLubyte's typedef, we see that it's actually unsigned char, which means that it takes integer values from 0 to 255. With sprite.opacity = 0.5 you implicitly convert floating point value to unsigned char, fractional part of 0.5 is truncated, and sprite.opacity becomes 0.

Upvotes: 13

Related Questions