gpt4 book ai didi

ios - 用 cocos2d 3 在圆圈中蒙版 Sprite

转载 作者:可可西里 更新时间:2023-11-01 04:52:01 25 4
gpt4 key购买 nike

自从我进一步了解后更新了我的问题。

我正在尝试用圆圈遮盖 Sprite ,下面的代码似乎有效。

    // Create the clipping node
self.clippingNode = [CCClippingNode clippingNodeWithStencil:[CCSprite spriteWithImageNamed:@"Home Scene/top-circle-mask.png"]];

self.clippingNode.alphaThreshold = 0;

// Add the image
[self.clippingNode addChild:self.maskedImage];

// And add the clipping node to the tree
[self addChild:self.clippingNode];

我还必须将此添加到我的 AppDelegate 中:

[cocos2dSetup setObject:@GL_DEPTH24_STENCIL8_OES forKey:CCSetupDepthFormat];

但是,“第一帧”渲染的图像未被屏蔽,所以看起来有点丑,我该如何解决?我制作了一个显示问题的小视频。 http://cl.ly/U3QF

我要这样看:

Masked image

谢谢

最佳答案

在CCSprite中不能直接设置带图片的圆形 Sprite 。因此您可以查看并将其添加到 CCScene 中。

首先你下载AGMedallionView类并添加到您的项目中。

在你的场景中导入那个类之后

#import "AGMedallionView.h"

在场景的初始化方法中

-(id) init
{
if( (self=[super init]) )
{
AGMedallionView *view1 = [[AGMedallionView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
[view1 setImage:[UIImage imageNamed:@"Icon-Small@2x.png"]];
view1.borderColor = [UIColor redColor];
view1.borderWidth = 5.0;
[[[CCDirector sharedDirector] view] addSubview:view1];
}
}

显示如下

enter image description here

关于ios - 用 cocos2d 3 在圆圈中蒙版 Sprite ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21940491/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com