2012-08-15 121 views
0

我有以下代码,我正在尝试向另一个图层添加一些Kineticj图层,但是当我什么也没有显示时。我在画布上添加了其他形状,如果分开添加所有图层,它们就会出现。这是一个错误还是我做错了什么?将图层添加到另一个图层

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(); 
+0

将图层放入另一个图层的目的是什么?将他们分组? – Delapouite 2012-08-16 05:53:29

+0

是的,正好对了 – soulBit 2012-08-17 07:01:52

回答

2

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

+0

谢谢,这就是我最终做的 - 奇怪的是文档没有提到这个限制 – soulBit 2012-08-31 11:10:44

相关问题