Pergunta

I am trying to use Hammer.js events within the Kinetic.js canvas and can't seem to get it working. I have tried both of the following:

var background = new Kinetic.Rect({
        x: 0,
        y: 0,
        width: image.getWidth(),
        height: image.getHeight(),
        id: "background",
        fill: 'rgba(159, 255, 200, 0.0)',
    });
    pointLayer.add(background);
    pointLayer.draw();

background.hammer().on('tap', function (e) {
        console.log("Background tapped");
});

OR

Hammer(background).on('tap', function (e) {
        console.log("Background tapped");
});

When using the first method, I get an error "has no method 'hammer'". The other I get no messages. Is it possible to use Hammer.js within the Kinetic.js canvas?

Foi útil?

Solução

It is posibble. But you can not listen kineticjs objects with hammer. You can listen documet elemets. For example canvas of layer or whole stage element.

var transformer = Hammer(stage.getContainer())  //kineticjs stage
transformer.on("transformstart", function(){
   // your code
});

Update:

Currently you can use KineticJS nodes and HammerJS events. (little patch need) First look at demo listed here: https://github.com/lavrton/KineticJS-HammerJS-test

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top