Cocos2D 中 glscissor 的对面? [英] Opposite of glscissor in Cocos2D?

查看:28
本文介绍了Cocos2D 中 glscissor 的对面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了一个名为 ClippingNode 的类,我可以在精灵上使用它来仅显示指定的矩形区域:https://github.com/njt1982/ClippingNode

I found a class called ClippingNode that I can use on sprites to only display a specified rectangular area: https://github.com/njt1982/ClippingNode

一个问题是我需要做完全相反的事情,这意味着我想要相反的.我希望显示指定矩形之外的所有内容,并取出里面的所有内容.

One problem is that I need to do exactly the opposite, meaning I want the inverse of that. I want everything outside of the specified rectangle to be displayed, and everything inside to be taken out.

在我的测试中,我使用了一个精灵的位置,它将更新帧,因此这需要发生,这意味着将定义新的剪辑矩形.

In my test I'm using a position of a sprite, which will update frame, so that will need to happen to meaning that new clipping rect will be defined.

CGRect menuBoundaryRect = CGRectMake(lightPuffClass.sprite.position.x, lightPuffClass.sprite.position.y, 100, 100);
ClippingNode *clipNode = [ClippingNode clippingNodeWithRect:menuBoundaryRect];

[clipNode addChild:darkMapSprite];
[self addChild:clipNode z:100];

我注意到里面有 ClippingNode 类 allocs,但我没有使用 ARC(项目太大太复杂,无法更新到 ARC),所以我想知道我还需要发布什么以及在哪里发布.

I noticed the ClippingNode class allocs inside but I'm not using ARC (project too big and complex to update to ARC) so I'm wondering what and where I'll need to release too.

我已经尝试了几个遮罩类,但是我遮罩的任何东西都适合整个精灵(我的精灵覆盖了整个屏幕.此外,遮罩需要移动,所以我认为如果我能得到 glscissor 将是一个不错的选择它做相反的事情.

I've tried a couple of masking classes but whatever I mask fits over the entire sprite (my sprite covers the entire screen. Additionally the mask will need to move, so I thought glscissor would be a good alternative if I can get it to do the inverse.

推荐答案

您不需要开箱即用的任何东西.

You don't need anything out of the box.

你必须定义一个带有模板的CCClippingNode,然后将它设置为inverted,你就完成了.我添加了一个胡萝卜精灵来展示如何在剪辑节点中添加精灵,以便将其考虑在内.

You have to define a CCClippingNode with a stencil, and then set it to be inverted, and you're done. I added a carrot sprite to show how to add sprites in the clipping node in order for it to be taken into account.

@implementation ClippingTestScene
{
    CCClippingNode *_clip;
}

以及实现部分

_clip = [[CCClippingNode alloc] initWithStencil:[CCSprite spriteWithImageNamed:@"white_board.png"]];
_clip.alphaThreshold = 1.0f;
_clip.inverted = YES;

_clip.position = ccp(self.boundingBox.size.width/2 , self.boundingBox.size.height/2);
[self addChild:_clip];

_img = [CCSprite spriteWithImageNamed:@"carrot.png"];
_img.position = ccp(-10.0f, 0.0f);
[_clip addChild:_img];

你必须设置一个额外的标志才能工作,但是 Cocos 会在控制台中吐出你需要做的事情.

You have to set an extra flag for this to work though, but Cocos will spit out what you need to do in the console.

这篇关于Cocos2D 中 glscissor 的对面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆