CreateJS:如何链接几个形状

时间:2016-02-18 16:20:52

标签: canvas createjs easeljs

我想通过一个命令使几个形状可拖动/可伸缩/可旋转同步。是否有内置函数来链接它们或使它们嵌套?或者我应该把它们放在一个数组中并在每个数组上迭代我的命令?

1 个答案:

答案 0 :(得分:2)

您可以向容器添加任意数量的显示对象,而是在容器上执行转换操作。

var shape = new createjs.Shape();
shape.graphics.f("#f00").dc(0,0,25);

var shape2 = new createjs.Shape();
shape2.graphics.f("#00f").dc(0,0,25);
shape2.x = 100;

var container = new createjs.Container();
container.addChild(shape, shape2);
stage.addChild(container);

container.x = container.y = 100;
container.rotation = 45;

// Move the container on the x-axis when dragged
container.on("pressmove", function(e) {
    container.x = stage.mouseX;
});

这是一个小提琴:http://jsfiddle.net/2m9yff9x/