Add magnifier to cocos2d games

I want to add a magnifying glass to cocos2d. here is what i found online: http://coffeeshopped.com/2010/03/a-simpler-magnifying-glass-loupe-view-for-the-iphone I changed the code a bit: (since I don’t want the magnifier to follow at our touch)

- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:magnifier_rect])) {
    // make the circle-shape outline with a nice border.
    self.layer.borderColor = [[UIColor lightGrayColor] CGColor];
    self.layer.borderWidth = 3;
    self.layer.cornerRadius = 250;
    self.layer.masksToBounds = YES;
    touchPoint = CGPointMake(CGRectGetMidX(magnifier_rect), CGRectGetMidY(magnifier_rect));
}
return self;
}

Then I want to add it to one of the init methods:

    loop = [[MagnifierView alloc] init];
    [loop setNeedsDisplay];
    loop.viewToMagnify = [CCDirector sharedDirector].openGLView;

    [[CCDirector sharedDirector].openGLView.superview addSubview:loop];

But the result: the area inside the magnifier is black. Also, this magnifier just zooms in at the same scale, how can I change it to zoom closer to the center and less close to the edge? (like a real magnifier) ​​Thank you!

+3
source share
2 answers

Here I assume that you want to increase the center of the screen.

.

CGSize size = [[CCDirector sharedDirector] winSize];

id lens = [CCLens3D actionWithPosition:ccp(size.width/2,size.height/2) radius:240 grid:ccg(15,10) duration:0.0f]; 

[self runAction:lens];
+2

Cocos2d OpenGL, CoreAnimation/Quartz. CALayer, , , . OpenGL , Christmann, , . CoreAnimation/Quartz, , .

+2

All Articles