Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>LayerB should use the <code>GL_SCISSOR_TEST</code> to trim the outside of itself. You can easily google for more information about it, it basically defines a <code>rect</code> and then uses <code>glScissor</code>on it to remove the outside. I have a class I extend when I need to do this, that goes as follows:</p> <pre><code>// // CCNodeClip.h // // Created by Ignacio Orlandoni on 7/29/11. // #import &lt;Foundation/Foundation.h&gt; #import "cocos2d.h" @interface CCNodeClip : CCLayer { } -(void)preVisit; -(void)postVisit; @end </code></pre> <p>-</p> <pre><code>// // CCNodeClip.m // // Created by Ignacio Orlandoni on 7/29/11. // #import "CCNodeClip.h" @implementation CCNodeClip -(void)visit { [self preVisit]; [super visit]; [self postVisit]; } -(void)preVisit { if (!self.visible) return; glEnable(GL_SCISSOR_TEST); CGPoint position = [self position]; //I don't remember if this rect really serves for both orientations, so you may need to change the order of the values here. CGRect scissorRect = CGRectMake(position.x, position.y, [self contentSize].width, [self contentSize].height); // CCLOG(@"Scrissor Rect: X: %02f, Y:%02f, W: %02f, H: %02f", scissorRect.origin.x, scissorRect.origin.y, scissorRect.size.width, scissorRect.size.height); // Handle Retina scissorRect = CC_RECT_POINTS_TO_PIXELS(scissorRect); glScissor((GLint) scissorRect.origin.x, (GLint) scissorRect.origin.y, (GLint) scissorRect.size.width, (GLint) scissorRect.size.height); } -(void)postVisit { glDisable(GL_SCISSOR_TEST); } @end </code></pre> <p>With that imported into <code>LayerB</code>, you can now define it as a <code>CCNodeClip</code> instead of <code>CCLayer</code>.</p> <p><strong>Some links...</strong></p> <p><a href="http://www.cocos2d-iphone.org/forum/topic/996" rel="nofollow noreferrer">glScissor &lt;&lt; cocos2d Forum</a></p> <p><a href="https://stackoverflow.com/questions/6914013/circle-shape-clipping-with-opengl-es-in-cocos2d">Circle shape clipping with opengl-es in cocos2d &lt;&lt; StackOverflow</a></p> <p><a href="https://stackoverflow.com/questions/3177751/cocos2d-iphone-sprite-cliping-mask-frame">Cocos2d iPhone - Sprite cliping/mask/frame &lt;&lt; StackOverflow</a></p> <p><a href="http://www.learn-cocos2d.com/tag/glscissor/" rel="nofollow noreferrer">Another Cocos2D gem: ClippingNode &lt;&lt; Learn-Cocos2d.com</a></p> <p><strong>As a side note...</strong></p> <p>CCScaleTo + CCMoveTo can be avoided if the anchor point for the sprite is centered, so the image stays centered in the container as it scales. (<code>.anchorPoint = ccp(0.5, 0.5);</code>)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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