如何克隆图像并将它们放在随机位置
How to clone an image and put them in random positions
我正在使用 create.js 将图像附加到我的页面。我想克隆它几次,然后把每一个都放在随机位置。我使用了 Jquery clone() 方法,但没有用。
function handleComplete(e)
var _obstacle = new createjs.Bitmap(queue.getResult("obstacle"));
_obstacle.x= Math.floor((Math.random() * 799) + 1);
_obstacle.y = Math.floor((Math.random() * 799) + 1);
stage.addChild(_obstacle);
}
function tickHandler(e) {
stage.update();
}
感谢关注!
@DeBanana说的对,方法是有的,不过是clone
。它将复制大多数 EaselJS 对象。
var bmp = otherBmp.clone();
对于有子对象或复杂内容的对象,有一个 "deep copy" 参数。
var container = otherContainer.clone(); // Just the container object and properties
var container = otherContainer.clone(true); // Includes children
http://www.createjs.com/docs/easeljs/classes/DisplayObject.html#method_clone
这是使用您的代码的简单 fiddle:http://jsfiddle.net/md2fx1t4/
干杯。
我正在使用 create.js 将图像附加到我的页面。我想克隆它几次,然后把每一个都放在随机位置。我使用了 Jquery clone() 方法,但没有用。
function handleComplete(e)
var _obstacle = new createjs.Bitmap(queue.getResult("obstacle"));
_obstacle.x= Math.floor((Math.random() * 799) + 1);
_obstacle.y = Math.floor((Math.random() * 799) + 1);
stage.addChild(_obstacle);
}
function tickHandler(e) {
stage.update();
}
感谢关注!
@DeBanana说的对,方法是有的,不过是clone
。它将复制大多数 EaselJS 对象。
var bmp = otherBmp.clone();
对于有子对象或复杂内容的对象,有一个 "deep copy" 参数。
var container = otherContainer.clone(); // Just the container object and properties
var container = otherContainer.clone(true); // Includes children
http://www.createjs.com/docs/easeljs/classes/DisplayObject.html#method_clone
这是使用您的代码的简单 fiddle:http://jsfiddle.net/md2fx1t4/
干杯。