cocos2d - 仅显示精灵的一部分 - 不规则形状
我真的很疯狂地试图解决这个问题,所以任何帮助将不胜感激。我试图隐藏大部分精灵并逐渐显示它。如果我只使用矩形,这效果很好。例如,我发现有人实现了“ClippingNode”类,并且效果很好,即这部分代码:
-(void) visit
{
glPushMatrix();
glEnable(GL_SCISSOR_TEST);
glScissor(clippingRegion.origin.x + positionInPixels_.x, clippingRegion.origin.y + positionInPixels_.y, clippingRegion.size.width, clippingRegion.size.height);
[super visit];
glDisable(GL_SCISSOR_TEST);
glPopMatrix();
}
问题是我需要一个不规则的形状,而不仅仅是一个矩形。我希望我可以堆叠对 glScissor 的调用并创建一个具有许多较小矩形的形状,但不幸的是 glScissor 只能工作一次(最后一次调用它时)。
看来cocos2d不支持OpenGLs模板缓冲区(是吗?),即使支持,我发现OpenGL很难理解,我仍然需要有人向我解释它。如果我可以在精灵上设置贝塞尔路径作为遮罩(我认为你可以在 Quartz 中做到),那就太好了,但似乎不支持这一点。
拜托,如果有人在这里有一点智慧,那就太好了!
I'm really going crazy trying to figure this out, so any help would be really appreciated. I'm trying to hide most of a sprite and show it gradually. This works fine if I only work with rectangles. For example, I found someone's implementation of the "ClippingNode" class and it worked well, namely, this part of the code:
-(void) visit
{
glPushMatrix();
glEnable(GL_SCISSOR_TEST);
glScissor(clippingRegion.origin.x + positionInPixels_.x, clippingRegion.origin.y + positionInPixels_.y, clippingRegion.size.width, clippingRegion.size.height);
[super visit];
glDisable(GL_SCISSOR_TEST);
glPopMatrix();
}
The problem is I need an irregular shape, not just a rectangle. I was hoping I could stack calls to glScissor and create a shape with many smaller rectangles, but unfortunately glScissor only works once (the last time it was called).
It seems that cocos2d doesn't support OpenGLs stencil buffer (does it?) and even if it did, I find OpenGL so hard to understand, I'd still need someone to explain it to me. If I could set a bezier path on the sprite as a mask (which I think you can do in Quartz), that would be great, but it doesn't seem like that's supported.
Please, if anyone has any bit of wisdom here, that'd be great!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
想通了。您可以多次调用 glScissor,您只需要每次都绘制剪刀形状:
Figured it out. You can call glScissor multiple times, you just also need to draw that scissored shape each time:
这对于 glScissor 来说是不可能的,但您可以使用模板缓冲区轻松实现这种效果。这是文档:
http://www.opengl。 org/resources/code/samples/sig99/advanced99/notes/node117.html
还有一个关于模板缓冲区的 NeHe 教程,但是它是在 C++ 中,而不是 Objective C 中(尽管它应该很容易翻译成您需要的任何应用程序):
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=26
编辑:这是基于您想要将其剪辑为任意形状的假设,例如星星,笑脸什么的,而不仅仅是一个矩形。
It isn't possible with glScissor, but you could easily achieve this effect using the stencil buffer. Here is the documentation:
http://www.opengl.org/resources/code/samples/sig99/advanced99/notes/node117.html
There is also a NeHe tutorial on the stencil buffer, but it is in C++, not Objective C (though it should be easy to translate into whatever application you need):
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=26
EDIT: This is based on the assumption that you want to clip it to some arbitrary shape, for example a star, smiley whatever, instead of just a rectangle.