cocos2d游戏中添加放大镜

2024-08-11移动开发问题
3

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

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

Cocos2d - 如何检查不同层中对象之间的交集
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)...
2024-08-12 移动开发问题
8

恢复游戏 cocos2d
Resume game cocos2d(恢复游戏 cocos2d)...
2024-08-12 移动开发问题
6

突出显示朗读文本(在 iPhone 的故事书类型应用程序中)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))...
2024-08-12 移动开发问题
9

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

如何将 32 位 PNG 转换为 RGB565?
How to convert 32 bit PNG to RGB565?(如何将 32 位 PNG 转换为 RGB565?)...
2024-08-12 移动开发问题
21