我想在cocos2d游戏中添加一个放大镜。这是我在网上找到的:http://coffeeshopped.com/2010/03/a-simpler-magnifying-glass-loupe-view-for-the-iphone我稍微修改了一下代码:(因为我不想让放大镜跟随我们的触摸)
- (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;
}然后我想把它添加到我的一个场景初始化方法中:
loop = [[MagnifierView alloc] init];
[loop setNeedsDisplay];
loop.viewToMagnify = [CCDirector sharedDirector].openGLView;
[[CCDirector sharedDirector].openGLView.superview addSubview:loop];但结果是:放大镜内部的区域是黑色的。另外,这个放大镜只是放大相同比例的图像,我如何改变它,使其在中心附近放大更多,在边缘附近放大更少?(就像真正的放大镜一样)谢谢!
发布于 2011-05-31 23:01:56
这里我假设你想放大屏幕的中心。
您必须根据您的应用程序需求动态更改大小属性以满足您的需要。
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];发布于 2011-05-30 23:02:52
Cocos2d使用OpenGL绘制,而不是核心动画/石英。您正在绘制的CALayer为空,因此您什么也看不到。您必须使用OpenGL图形代码来执行放大镜效果,或者对像素进行采样并适当地更改它们以实现放大效果,就像您链接的文章中引用的the Christmann article中所做的那样。该代码还依赖于CoreAnimation/Quartz,因此您需要找到另一种方法来获得您希望放大的图像数据。
https://stackoverflow.com/questions/6174882
复制相似问题