简体   繁体   English

用HammerJS多点触控旋转的dynamicJs形状

[英]kineticJs shape with hammerjs multitouch rotation

Trying to binb hammerJs multi-touch into my current kineticJs 5.1 codes, found tips, but my puzzle pieces does not rotate at all, and my pieces are kinetic shape, why? 尝试将HamsJs的多点触控绑定到当前的dynamicJs 5.1代码中,找到了提示,但是我的拼图块根本不旋转,并且我的拼图块是动力学形状,为什么?

            var startRotate = 0;
            var hammertime = Hammer(piecesArray[i][j].shape);
            hammertime.on("transformstart", function(e) {
            startRotate = piecesArray[i][j].shape.rotation();
            }).on("transformstart", function(e) {
               piecesArray[i][j].shape.rotation(startRotate + e.gesture.rotation);
               layer.draw();
            }); 

my fiddle : http://jsfiddle.net/e70n2693/20/ 我的小提琴: http : //jsfiddle.net/e70n2693/20/

use the latest version of hammer.js v2.0. 使用最新版本的Hammer.js v2.0。

check out the getting started guide . 查看入门指南 "The pinch and rotate gestures are disabled by default, enable it by" “默认情况下,禁用捏和旋转手势,请启用它”

hammertime.get('pinch').set({ enable: true });
hammertime.get('rotate').set({ enable: true });

Here's an updated jsfiddle . 这是更新的 jsfiddle I couldn't test it though, i can't make a rotate gesture, hope it works. 我无法测试,但无法做出旋转手势,希望它能正常工作。

Edit : 编辑

The problem is, Hammer(imageObj, options); 问题是Hammer(imageObj, options); api expects imageObj to be an html element, in your case it's a kinetic shape. api希望imageObj是html元素,在您的情况下,它是动态形状。 I don't know if you can get the html elements for each kinetic shapes. 我不知道您是否可以获得每种动力学形状的html元素。 If not, you can listen to rotation on the .kinetic-container canvas element. 如果没有,您可以在.kinetic-container canvas元素上收听旋转。 So the rotation gesture is performed on the whole canvas, and you have to keep track of the last touched kinetic shape so you can rotate it. 因此,旋转手势是在整个画布上执行的,因此您必须跟踪最后触摸的动力学形状,才能旋转它。

I've setup a refactored jsfiddle , showing the ideas i mentioned, however i couldn't manage to rotate the shape using kinetic, i hope this will fix your problem, again i couldn't test it for rotate but it works for tap . 我已经设置了一个重构的jsfiddle ,显示了我提到的想法,但是我无法通过动力学来旋转形状,我希望这可以解决您的问题,同样我无法对其进行rotate测试,但可以用于tap

This example is for KineticJS v5.1.0 and HammerJS v1.0.7 本示例适用于KineticJS v5.1.0和HammerJS v1.0.7

You have to apply Hammer instance on Kinetic.Node instance, not on Image object. 您必须将Hammer实例应用于Kinetic.Node实例,而不是Image对象。

var hammertime = Hammer(piecesArray[i][j].shape);
hammertime.on("transformstart", function(e) {
    this.startRatation = this.rotation();
}).on("transform", function(e) {
    this.rotation((this.startRatation || 0) + e.gesture.rotation);
    this.getLayer().draw();
});

http://jsfiddle.net/e70n2693/30/ http://jsfiddle.net/e70n2693/30/

Note: I think it is better to set another center for shape via offset . 注意:我认为最好通过offset设置形状的另一个center

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

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