Cocos2d iPhone - 雪碧剪贴/面具/框架 [英] Cocos2d iPhone - Sprite cliping/mask/frame
问题描述
我如何剪辑/裁剪/掩码或只是设置CCSprite在Cocos2D的框架?
how can i clip/crop/mask or just set the frame of a CCSprite in Cocos2D?
类似于:
设置UIView ,with clipping subviews = TRUE
Something similar to: setting the frame for UIView, with clipping subviews = TRUE
我的CCSprite 主sprite 已添加多个子sprite 。
我只希望主 Sprite Sprite 部分的掩码可见。
有没有办法剪辑或使用CCSprite的面具?
My CCSprite Main Sprite have multiple Child Sprite added to it. I only want Mask part of that Main Sprite Sprite visible. Is there a way to clip or use a mask for CCSprite?
我可以剪切顶部的背景和图层,只留下可见区域,但是这是唯一的方法吗?
I could cut the background and layer that on top, leaving only that visible area, but is that the only way?!
这里是一个示例图像演示我试图实现:
here's a sample image demonstrating what I'm trying to achieve:
推荐答案
我最终使用GL_SCISSOR。
I ended up using GL_SCISSOR.
在MainSprite中我受到影响:
in MainSprite I impemented:
- (void) visit
{
if (!self.visible) {
return;
}
glEnable(GL_SCISSOR_TEST);
glScissor(x, y, width, height);
[super visit];
glDisable(GL_SCISSOR_TEST);
}
这将剪辑或遮盖指定区域。
This will clip or mask the specified area.
唯一棘手的是,在横向模式下,Cocos2D在屏幕的左下角有0,0,而OpenGL在右下角有它不考虑屏幕的方向。
The only tricky bit is that in Landscape mode Cocos2D has 0,0 at the bottom-left side of the screen, while OpenGL has it at the bottom-right corner as it doesn't consider the orientation of the screen.
换句话说,对于OpenGL,考虑你有一个旋转的肖像屏幕。
In other words, for OpenGL consider you have a rotated portrait Screen.
这篇关于Cocos2d iPhone - 雪碧剪贴/面具/框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!