[英]How to copy and paste shapes in KineticJS
I have a button1 like this. 我有一个像这样的button1。
var Button1 = new Kinetic.Polygon({
points: [0, 0, 0, 30, 15, 15],
fill: 'rgb(0, 255, 0)'
});
Now I want to copy it (duplicate it). 现在,我要复制(复制)。 How would I do that?
我该怎么做?
I tried this - 我试过了-
var Button2 = new Kinetic.Polygon();
Button2 = Button1;
This did not work as only one copy is being drawn on the canvas. 由于在画布上仅绘制了一个副本,因此无法使用。
How should I do this? 我应该怎么做?
The simplest way to copy an object in KineticJS is to use the clone method: 在KineticJS中复制对象的最简单方法是使用clone方法:
var Button1 = new Kinetic.Polygon({
points: [0, 0, 0, 30, 15, 15],
fill: 'rgb(0, 255, 0)'
});
var Button2 = Button1.clone();
Button2 is now an exact copy of Button1 现在,Button2是Button1的精确副本
What about this: 那这个呢:
var buttonData = {
points: [0, 0, 0, 30, 15, 15],
fill: 'rgb(0, 255, 0)'
}
var Button1 = new Kinect.Polygon(buttonData);
var Button2 = new Kinect.Polygon(buttonData);
? ?
Button1 and Button2 now point to the same Kinetic object. 现在,Button1和Button2指向同一个动力学对象。
You can try to use jQuery extend method 您可以尝试使用jQuery扩展方法
var Button2 = $.extend({}, Button1);
This will make a copy of the object. 这将复制该对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.