【发布时间】:2014-06-13 07:28:01
【问题描述】:
我不能剪辑一个简单的精灵。我正在使用 Cocos2d-x 3.1rc0。这是代码。
local sprite = cc.Sprite:create("red-box.png")
local shape = cc.DrawNode:create()
shape:drawPolygon({cc.p(0, 0), cc.p(0, 100), cc.p(100, 100), cc.p(100, 0), cc.p(0, 0)}, 5, cc.c4b(0, 0, 0, 1), 0, cc.c4b(0, 0, 0, 1))
local clipper = cc.ClippingNode:create(shape)
clipper:setContentSize(sprite:getContentSize())
clipper:setScale(0.25)
clipper:setGlobalZOrder(20)
clipper:setPosition(10, 10)
clipper:setInverted(true)
clipper:addChild(sprite)
gameLayer:addChild(clipper)
这与问题中使用的模式相同:
- Opposite of glscissor in Cocos2D?
- Cocos2d-x - how to set part of CCLayer transparent?
- http://www.onemoresoftwareblog.com/2013/12/cocos2d-x-ccclippingnode-triple-c.html(提供了一个很好的例子)
这是描述问题的图片:
我尝试了各种不同的组合,例如设置 clipper:setAlphaThreshold(0)。我什至尝试实现这个人的代码:
顺便说一下,depthFormat 设置为 GL_DEPTH24_STENCIL8_OES。所以这不是问题。
另外,为什么模具的绘制是从中间开始而不是从左下角开始?我设置了理发器的锚点和形状,但无法移动。困惑。
这是我的 AppController.mm 代码:
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [window bounds]
pixelFormat: kEAGLColorFormatRGBA8
depthFormat: GL_DEPTH24_STENCIL8_OES
preserveBackbuffer: NO
sharegroup: nil
multiSampling: NO
numberOfSamples: 0 ];
[eaglView setMultipleTouchEnabled:YES];
// Use RootViewController manage CCEAGLView
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
viewController.wantsFullScreenLayout = YES;
viewController.view = eaglView;
// Set RootViewController to window
if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
{
// warning: addSubView doesn't work on iOS6
[window addSubview: viewController.view];
}
else
{
// use this method on ios6
[window setRootViewController:viewController];
}
[window makeKeyAndVisible];
[[UIApplication sharedApplication] setStatusBarHidden: YES];
// IMPORTANT: Setting the GLView should be done after creating the RootViewController
cocos2d::GLView *glview = cocos2d::GLView::createWithEAGLView(eaglView);
cocos2d::Director::getInstance()->setOpenGLView(glview);
cocos2d::Application::getInstance()->run();
return YES;
【问题讨论】: