Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It only needs CCRenderTexture to finish the job. Any suggestion will be greatly appreciated.</p> <p>ClippingNode.h</p> <pre><code>#import "cocos2d.h" @interface ClippingNode : CCNode @property (nonatomic, assign) CGSize clippingSize; @end </code></pre> <p>ClippingNode.m</p> <pre><code>#import "ClippingNode.h" @interface ClippingNode() @property (nonatomic, strong) CCRenderTexture * renderTexture; @property (nonatomic, strong) CCSprite * clippedSprite; @end @implementation ClippingNode @synthesize renderTexture; @synthesize clippedSprite; @synthesize clippingSize; - (void) setClippingSize:(CGSize)newClippingSize { //assignment clippingSize = newClippingSize; //set contentSize self.contentSize = clippingSize; //configure renderTexture self.renderTexture = [CCRenderTexture renderTextureWithWidth:clippingSize.width height:clippingSize.height]; renderTexture.contentSize = CGSizeMake(clippingSize.width, clippingSize.height); //configure the renderTexture sprite self.clippedSprite = [CCSprite spriteWithTexture:renderTexture.sprite.texture]; clippedSprite.position = self.position; clippedSprite.rotation = rotation_; clippedSprite.scaleY = -1; } - (void)visit { [renderTexture beginWithClear:0 g:0 b:0 a:1]; [super visit]; [renderTexture end]; [clippedSprite visit]; } @end </code></pre> <p>Usage:</p> <pre><code>CCSprite * spriteImage = ...; spriteImage.position = ccp(0,0); spriteImage.anchorPoint = ccp(0.5,0.5); //configure clipping Node self.clippingNode = [ClippingNode node]; clippingNode.position = ccp(size.width * 0.5f, size.height * 0.5f); clippingNode.anchorPoint = ccp(0.5f, 0.5f); clippingNode.rotation = -10.0f; //configure clipping region [clippingNode setClippingSize:CGSizeMult(spriteImage.boundingBox.size, 1.5f)]; //add content to the clipping node [clippingNode addChild:spriteImage] </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload