问题描述
我想在cocos2d游戏中添加一个放大镜。这里是我在网上找到:
我已经改变了一点代码:(since我不想让放大镜跟随我们)
i want to add a magnifier in cocos2d game. here is what i found online:http://coffeeshopped.com/2010/03/a-simpler-magnifying-glass-loupe-view-for-the-iphoneI've changed the code a bit:(since i don't want to let the loupe follow 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;
}
然后我想将它添加到我的一个场景init方法: p>
Then i want to add it in one of my scene init method:
loop = [[MagnifierView alloc] init];
[loop setNeedsDisplay];
loop.viewToMagnify = [CCDirector sharedDirector].openGLView;
[[CCDirector sharedDirector].openGLView.superview addSubview:loop];
但结果是:放大镜内的区域是黑色的。
这个放大镜只是放大图像具有相同的规模,我怎么能改变它放大更靠近中心和更少的边缘附近? (就像真正的放大镜)
谢谢!!!
But the result is: the area inside the loupe is black.Also this loupe just magnify images with the same scale, how can i change it to magnify more near the center and less near the edge? (just like real magnifier)Thank you !!!
推荐答案
这里我假设你想放大中心
Here I assume that you want to magnify the center of the screen.
您必须根据应用程式的需求,将动态大小属性变更为您的愿望。
You have to change dynamically size attribute to your wishes according to your app needs.
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];
这篇关于在cocos2d游戏中添加一个放大镜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!