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

问题描述

我发现了一个名为ClippingNode的类,我可以在sprite上使用它来显示指定的矩形区域:



一个问题是,我需要做完全相反的事情,这意味着我想要相反的。我想要显示指定矩形之外的所有内容,并且将内部的一切都取出。



在我的测试中,我使用一个精灵的位置,这将更新帧,所以这将需要发生,意味着将定义新的剪辑矩形。 / p>

  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类在内部分配,但我不使用ARC(项目太大和复杂



我尝试了几个掩蔽类,但是我掩盖了整个精灵(我的精灵覆盖整个屏幕。此外,面具将需要移动,所以我认为glscissor将是一个很好的选择,如果我可以得到它做逆。



您必须定义一个 CCClippingNode 使用模板,然后将其设置为 inverted ,你完成了我添加了一个胡萝卜精灵来展示如何添加精灵在剪切节点中,以便将其考虑在内。

  @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会吐出你需要的在控制台中执行。


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];

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.

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.

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;
}

And the implementation part

_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];

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的对面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 16:00