Note that there are some explanatory texts on larger screens.

plurals
  1. POCocos2D magnification - making the code dynamic and using an image
    primarykey
    data
    text
    <p>I have found the following code and I need help with editing it. I am not really familiar with texture rendering. </p> <p>First of all, init method takes a rect and magnifies only that area? How can I make it more dynamic and magnify only whatever is underneath the magnifying glass?</p> <p>Secondly, Is it possible to change the shape to circle rather than rectangle? Or Can I use an image as the frame of the magnifying glass?</p> <p>Here is the code..</p> <p>Cheers..</p> <p>.h file</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; #import "cocos2d.h" @interface Magnify : CCNode { BOOL active; CGRect rect; CGFloat magnifyScale; CCNode *renderNode; CCRenderTexture *renderTexture; } - (id)initWithNodeToMagnify:(CCNode *)n rect:(CGRect)rectToMagnify scale:(CGFloat)scale; - (void)enable; - (void)disable; </code></pre> <p>.m file</p> <pre><code>#import "Magnify.h" @implementation Magnify - (id)initWithNodeToMagnify:(CCNode *)n rect:(CGRect)rectToMagnify scale:(CGFloat)scale { if (self = [super init]) { self.visible = active = NO; renderNode = n; rect = rectToMagnify; magnifyScale = scale; renderTexture = [[CCRenderTexture renderTextureWithWidth:rect.size.width height:rect.size.height] retain]; [self addChild:renderTexture]; } return self; } - (void)enable { self.visible = active = YES; [self scheduleUpdate]; } - (void)disable { self.visible = active = NO; [self unscheduleUpdate]; } - (void)drawAreaToTexture { [renderTexture beginWithClear:0.0 g:0.0 b:0.0 a:1.0]; // shift the renderNode's position to capture exactly the rect we need CGPoint originalPosition = renderNode.position; renderNode.position = ccpSub(originalPosition, rect.origin); // scale the node as we want CGFloat originalScale = renderNode.scale; renderNode.scale = magnifyScale; [renderNode visit]; // shift renderNode's position back renderNode.position = originalPosition; // scale back renderNode.scale = originalScale; [renderTexture end]; } - (void)update:(ccTime)dt { [self drawAreaToTexture]; } - (void)dealloc { [renderTexture release]; [super dealloc]; } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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