3.4 关于clippingNode的问题

local scene=cc.Scene:create()
cc.Director:getInstance():runWithScene(scene)
local layer=cc.Layer:create()
scene:addChild(layer)
local stencil = cc.DrawNode:create()
stencil:drawPolygon({cc.p(50,50),cc.p(100,50),cc.p(100,100),cc.p(50,100)},4,cc.c4f(0,0,0,0),1,cc.c4f(0,0,0,0))
local c1=cc.Node:create()
c1:addChild(stencil)
local d1=cc.ClippingNode:create(c1)
layer:addChild(d1)
local a=cc.Sprite:create(“bg.png”)
a:setPosition(cc.p(0,0))
d1:addChild(a)

在cocos2d-x 3.4里面,为什么这样的操作,会使背景变白,裁剪失效了呢

不知道。不过推荐你用ClippingRectangleNode。
local crn=cc.ClippingRectangleNode:create(Rect(50,50,50,50));
layer:addChild(crn);
Lua不太会。就是仿着写的。

ClippingRectangleNode 是没有问题的
但是我要用到CCClippingNode的setInverted 这个功能

我用C++翻译了一下,在Mac端是没问题的。

请问你是在什么机器上出现的问题?

我在win32上运行的 ,和楼主一样,白色底,无剪切效果,好蛋 疼。

楼主问题解决了么? 我也遇到同样问题呀~~

local crn=cc.ClippingRectangleNode:create(Rect(50,50,50,50));
改为
local crn=cc.ClippingRectangleNode:create(cc.rect(50,50,50,50));
前面两个代表x,y 后面代表框的height width
这样就对了。
最后我采用这种方法

这样只能正方形,没有不规则的clip么

楼主解决没有啊?我也是遇到这个问题,不过后台提示stencil buffer is not enabled。
好像是因为这个才出现裁剪无效的,但是我尝试了网上说的修改Appcontroller.mm来打开stencil buffer,依然提示这个。
不知道有哪位高人能帮助解答下,到底是要怎么处理这个问题~:2:

这样的解答治标不治本啊,何况要用到不规则的裁剪

我在他们那里找到一个方法解决windows上的这个问题.
在C++ class中找到SimulaterWin.cpp 中实例化Appdelegate的代码,在后面添加_app->initGLContextAttrs();我的是第234行
Appdelegate重写initGLContextAttrs这个方法没有达到预期的效果,要手动调用一次

椭圆可以通过圆形拉伸。以此类推。