cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.24k stars 7.06k forks source link

ClippingNode broken on Canvas if position changes #16834

Open soccerob opened 8 years ago

soccerob commented 8 years ago

Steps to Reproduce:

  1. Add the following code into app.js ctor method
        var bgWhite = new cc.LayerColor( cc.color.WHITE, 200, 200 );
        // WILL WORK IF THESE ARE BOTH SET TO 0
        bgWhite.x = 110;
        bgWhite.y = 110;

        var maskLayer = new cc.ClippingNode( new cc.LayerColor(cc.color.WHITE, 200, 200));
        maskLayer.x = bgWhite.x;
        maskLayer.y = bgWhite.y;

        this.addChild(bgWhite);
        this.addChild(maskLayer);

        var item = new cc.LayerColor( cc.color.RED, 100, 100 );
        item.x = -200;
        item.y = -200;
        this.item = item;
        maskLayer.addChild(item);

        var move1 = cc.MoveTo.create( 1, cc.p(400, 400));
        var move2 = cc.MoveTo.create( 1, cc.p(-200, -200));
        var sequence = new cc.Sequence(move1, move2);
        var repeat = cc.RepeatForever.create( sequence );
        item.runAction(repeat);
  1. change project.json renderMode property to 1 (canvas) and 2 (WebGL) results are different in each render mode
soccerob commented 8 years ago

Note, I was able to "fix" this issue on Canvas by creating a variable for the node that is passed in to the ClippingNode constructor, and setting the position of that node to the preferred x and y. It seems I'll have to set some conditional blocks based on whether it's WebGL or Canvas.... would still prefer to have this fixed behind the scenes if it's possible.

        var testNode = new cc.LayerColor(cc.color.WHITE, 200, 200);
        testNode.x = bgWhite.x;
        testNode.y = bgWhite.y;

        var maskLayer = new cc.ClippingNode( testNode );
        maskLayer.boundingBox().x = bgWhite.x;
        maskLayer.boundingBox().y = bgWhite.y;