Per @Gob00st request, I will add a very simple magnifier class to show the basic idea behind it. It currently takes a rect that will be used as the magnified area, but it doesn't take into account the scale, so this needs to be adjusted. But the basic idea remains the same.
Magnifier.h
#import <Foundation/Foundation.h>
#import "cocos2d.h"
@interface Magnifier : CCNode {
BOOL active; // boolean for determining if magnifier is active (visible) or not
CGRect rect; // rect on the screen to magnify
CGFloat magnifyScale; // the scale we want to magnify
CCNode *renderNode; // the node to be drawn on texture
CCRenderTexture *renderTexture; // a CCRenderTexture object
}
- (id)initWithNodeToMagnify:(CCNode *)n rect:(CGRect)rectToMagnify scale:(CGFloat)scale;
- (void)enable;
- (void)disable;
@end
Magnifier.m
#import "Magnifier.h"
@implementation Magnifier
- (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
Example on how to use it. This uses the right bottom area of the screen and displays it in the left bottom:
// init magnifier
CGRect magnifierRect = CGRectMake([CCDirector sharedDirector].winSize.width-100.0f, 0.0f, 100.0f, 100.0f);
Magnifier *magnifier = [[Magnifier alloc] initWithNodeToMagnify:self rect:magnifierRect scale:1.0f];
magnifier.position = ccp(magnifierRect.size.width*0.5f, magnifierRect.size.height*0.5f);
[self addChild:magnifier];
// enable magnifier
[magnifier enable];