1

I'm clipping my sprite with this code:

//At my CCSprite subclass m.

-(void)visit
{
CGPoint worldOrg = [self convertToWorldSpace:ccp(0, 0)];
CGPoint dest = [self convertToWorldSpace:ccp(self.contentSize.width, self.contentSize.height)];
CGPoint dims = ccpSub(dest, worldOrg);

glEnable(GL_SCISSOR_TEST);

glScissor(worldOrg.x, worldOrg.y, dims.x, dims.y);

#define SHOW_CLIPPED_AREA 1

#if SHOW_CLIPPED_AREA
//Draws a red rectangle showing clipped area
ccDrawSolidRect(ccp(0, 0), ccp(1024, 1024), ccc4f(64, 0, 0, 128));
#endif
[super visit];

glDisable(GL_SCISSOR_TEST);
}

Then just create the sprite as usual, adjust the sprite.contentSize property to whatever I need:

CCSprite aSprite = [CCSprite spriteWith...];
aSprite.contentSize = CGSizeMake(20,20);
//Add it to my layer
[self addChild:aSprite];

And it works as expected!

Problem...

When adding it to a CCSpriteBatchNode, it wont clip the sprite... it shows the sprite but without clipping it.

Can someone please help me out with this, I've googled everywhere with no answer to this.

I've also used the ClippingNode class from Steffen Itterheim, but I'm also having issues adding it to a CCSpriteBatchNode.

Any help will be appreciated.

1 Answers1

0

Clipping or any custom drawing won't work with sprite-batched sprites.

The CCSpriteBatchNode will not call visit (nor draw) methods on their children because the batch node takes over rendering of the children. Therefore any code you write in draw or visit methods of a CCSprite will have no effect when you sprite-batch the sprite.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • Thanks for your explanation, I guess I'll have to add them directly to the main layer. Is there a better approach for that? Thanks again! – Juan Ramirez Feb 10 '13 at 00:36