cocos2d游戏中添加放大镜

Add a magnifier in cocos2d games(cocos2d游戏中添加放大镜)

本文介绍了cocos2d游戏中添加放大镜的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 cocos2d 游戏中添加放大镜.这是我在网上找到的:http://coffeeshopped.com/2010/03/a-simple-magnifying-glass-loupe-view-for-the-iphone我稍微修改了代码:(因为我不想让放大镜跟随我们的触摸)

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-iphone I'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;
}

然后我想将它添加到我的场景初始化方法之一中:

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游戏中添加放大镜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:cocos2d游戏中添加放大镜

基础教程推荐