简体   繁体   English

KineticJS - Shape.setPosition();

[英]KineticJS - Shape.setPosition();

I'm having a bit of trouble playing around with KineticJS. 我在使用KineticJS时遇到了一些麻烦。

As you can see from my fiddle , I am able to access the Shape object (box) inside of my drop event, to get the x,y coordinates, and I'm performing math on them to get the new coordinates I want to 'snap' the shape to, but I can't figure out how on earth to set the position and redraw the box. 正如你从我的小提琴中看到的,我能够访问我的drop事件中的Shape对象(框),获取x,y坐标,我正在对它们进行数学运算以获得我想要的新坐标'捕捉'形状,但我无法弄清楚如何设置位置和重绘框。

The docs are sparse, at best: 文档很稀疏,充其量:

http://www.kineticjs.com/api-docs.php (See Shape.setPosition( x, y)) http://www.kineticjs.com/api-docs.php (参见Shape.setPosition(x,y))

Has anyone here messed with this library yet? 有没有人在这乱搞这个图书馆呢?

EDIT: My now working fiddle: http://jsfiddle.net/Programmer/m4MZk/ 编辑:我现在工作的小提琴: http//jsfiddle.net/Programmer/m4MZk/

check out the "Animals on the Beach" lab which is an example of snapping shape objects into place based on their coordinates: 查看“海滩上的动物”实验室,这是根据坐标将形状对象捕捉到位的示例:

http://www.html5canvastutorials.com/labs/html5-canvas-animals-on-the-beach-game-with-kineticjs/ http://www.html5canvastutorials.com/labs/html5-canvas-animals-on-the-beach-game-with-kineticjs/

This worked for me and has now been extended into a full circuit diagram drawing app. 这对我有用,现在已经扩展到完整的电路图绘图应用程序。

It's based on the Animals on the Beach code but a bit simpler. 它基于海滩上的动物代码,但有点简单。

http://reviseomatic.org/help/e-tools/Diagram%20Designer%20Circuits.php http://reviseomatic.org/help/e-tools/Diagram%20Designer%20Circuits.php

wire1vImg.on('dragend', function() {
  var point = wire1vImg.getPosition();
  var newX = Math.round(point.x / 15) * 15;
  var newY = Math.round(point.y / 15) * 15;
  wire1vImg.setPosition(newX, newY);
  stage.draw();
}); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM