Hi,
Reading some topic in the forum, I changed my approach of using cc.Graphics to a combination of cc.Sprite + cc.Mask to achieve simple shapes that could be faded using cc.tween.
My issue now is that after resizing the node that contains the mask, the shape (in this case a circle) is lost. Tried putting maskInit inside update to redraw the mask with no success. The structure is as follows:
Node
- cc.Mask
- ChildNode
-
- cc.Sprite
// Inside onLoad
spriteInit() {
this.node.width = this.node.height = 40;
cc.resources.load("textures/pixel", cc.SpriteFrame, null, (err, spriteFrame) => {
const node = new cc.Node();
const sprite = node.addComponent(cc.Sprite);
sprite.spriteFrame = spriteFrame;
// Add spriteNode to this node.
this.node.addChild(node);
node.width = node.height = this.node.width;
});
},
maskInit(isNew = false) {
const mask = isNew ? this.node.addComponent(cc.Mask) : this.node.getComponent(cc.Mask);
mask._graphics.clear();
mask._graphics.circle(0, 0, this.node.width / 2);
mask._graphics.fillColor = cc.Color.BLACK;
mask._graphics.lineWidth = 1;
mask._graphics.fill();
mask._graphics.stroke();
},
// Inside start
dynamicSize() {
cc.tween(this.node)
.repeatForever(
cc.tween().to(2, { scale: 2 })
.to(2, { scale: 1 })
)
.start()
}
EDIT: Seems like adding a parent node to this structure and scaling/moving the parent node prevents the issue from happening.