将图层添加到另一个图层

Add Layer to another Layer

本文关键字:图层 另一个 添加      更新时间:2023-09-26

我有以下代码,我试图将一些 Kineticjs 层添加到另一个层,但当我不做时什么都没有显示。我向画布添加了其他形状,这些形状显示正常,如果我单独添加所有图层,则它们会出现。这是一个错误还是我做错了什么?

this.canvas = new Kinetic.Stage({ "container": jQuery( "#testElement" ).get(0),
    "width": ShooterGame.WIDTH, "height": ShooterGame.HEIGHT });
this.container = new Kinetic.Layer();
this.layer1 = new Kinetic.Layer();
this.layer2 = new Kinetic.Layer();
this.layer3 = new Kinetic.Layer();
this.layer1Bg = new Kinetic.Rect({ "width": 100, "height": 100, "fill": "#FF0000" });
this.layer2Bg = new Kinetic.Rect({ "width": 100, "height": 100, "fill": "#FF0000" });
this.layer3Bg = new Kinetic.Rect({ "width": 100, "height": 100, "fill": "#FF0000" });
this.layer1.add( this.layer1Bg );
this.layer2.add( this.layer2Bg );
this.layer3.add( this.layer3Bg );
this.container.add( this.layer1 );
this.container.add( this.layer2 );
this.container.add( this.layer3 );
this.canvas.add( this.container );
this.container.draw();

您可以将图层添加到组 (Kinetic.Group),然后将该组添加到舞台。