Skip to content

Instantly share code, notes, and snippets.

@zaneclaes
Created December 14, 2013 21:39
Show Gist options
  • Save zaneclaes/7965245 to your computer and use it in GitHub Desktop.
Save zaneclaes/7965245 to your computer and use it in GitHub Desktop.
Basic sprite masking
- (void)visit {
if(self.mask) {
self.bakedTexture = [CCRenderTexture renderTextureWithWidth:self.contentSize.width
height:self.contentSize.height];
self.bakedTexture.position = ccp(self.contentSize.width/2,self.contentSize.height/2);
[self.mask setBlendFunc:(ccBlendFunc){GL_ONE, GL_ZERO}];
[self.bakedTexture begin];
[self.mask visit];
for(CCSprite *sprite in self.assets) {
[sprite setBlendFunc:(ccBlendFunc){GL_DST_ALPHA, GL_ZERO}];
[sprite visit];
}
[self.bakedTexture end];
[self addChild:self.bakedTexture];
self.mask = nil;// Don't do this again...
}
[super visit];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment