views:

9

answers:

1

Here is what my code look like

CCSprite *sp = [CCSprite spriteWithFile:@"textureWithOneColorbackground.jpg"];

[self addChild:sp];

// Change the blending factors
[sp setBlendFunc:(ccBlendFunc){GL_ONE, GL_ONE}];
[sp setColor:ccBLACK];

The original texture color is (246,149,32) The outcome now is (0, 0, 0)

According to OpenGL, the calculation should be like this: ((246 * 1 + 0 * 1), (149 * 1 + 0 * 1), (32 * 1 + 0 * 1)) So it should be the same.

Don't know why I am doing wrong here, can someone help me out?

Regards,

A: 

According to the docs:

http://www.cocos2d-iphone.org/api-ref/0.99.0/interface_c_c_sprite.html#af0c786f0f5b4081a4524e78eda9c8734

The Blending function property belongs to CCSpriteSheet, so you can't individually set the blending function property.

You seem to be applying it to the sprite and not the sheet. Try applying the blend to the sheet.

No one in particular
The sprite image is loading from file, as you can see from my code, so it means it is not using spritesheet. If you look further down, the doc says "If the parent is an standard CCNode, then CCSprite behaves like any other CCNode:It supports blending functionsIt supports aliasing / antialiasingBut the rendering will be slower" Also, spritesheet blending means one blending will affect the whole sheet, because it has only one texture. The blending will still work, just to the whole sheet, instead of individual sprites.
Leo
(I should learn to read.) There's a method -(void)useSelfRender. After creating the sprite you might need to call this first on it.
No one in particular