在Kinetic.Line上检测鼠标事件 [英] Detecting mouse events on Kinetic.Line

查看:117
本文介绍了在Kinetic.Line上检测鼠标事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试检测 Kinetic.Group 上的鼠标事件(当前是mousedown),其中包含由 Kinetic.Line

I'm trying to detect mouse events (currently mousedown) on a Kinetic.Group containing a grid made of Kinetic.Line's

我正在听Layer上的mousedown事件。当碰到一条线时,没有事件被触发。

I'm listening to the mousedown event on the Layer. When it happens that i hit a line, no event is fired.

var grid = new Kinetic.Group({
    x: 0,
    y: 0,
    width: this.group.width(),
    height: this.group.height()
});

grid.on("mousedown", function(){
    alert("At least this one should fire!");
});

var gridX = this.gridWidth, gridY = this.gridHeight;

this.group.add(grid);

while(gridY < this.rect.height()){          

    var line = new Kinetic.Line({
        points : [0,gridY, this.rect.width(), gridY],
        stroke: "grey",
        strokeWidth: 1
    });

    grid.add(line);

    gridY += this.gridHeight;
}

while(gridX < this.rect.width()){           
    var line = new Kinetic.Line({
        points : [gridX,0, gridX, this.rect.height()],
        stroke: "grey",
        strokeWidth: 1
    });

    grid.add(line);

    gridX += this.gridWidth;
}

我发现这个帖子:

Kinetic.Line mouseover

提到的答案是在形状上使用saveData()。这似乎是旧的,因为 Kinetic.Shape 中不存在此方法。

The answer mentioned there is using "saveData()" on the shape. This seems to be old because this method does not exist in Kinetic.Shape.

以上帖子的示例指的是图像。它使用 cache()方法创建一个命中图或其他东西。我尝试过我的线路,但这也行不通。

The example where the above post is pointing to is for images. And it uses the cache() method to create a hit graph or something. I tried that for my lines but this won't work either.

如何在Kinetic.Line上检测鼠标事件?

How can i simply detect mouse events on a Kinetic.Line?

推荐答案

万一你还在寻找这个@Chris的答案,如果其他人找到了你的帖子,我相信你和我都是一样的问题。 @Sjiep如此慷慨地在这个帖子中解决了我的问题。

Just in case you are still looking for an answer to this @Chris, and in case others find your thread, I believe you and I were suffering from the same issue. @Sjiep so graciously provided a fix for my problem under this thread.

原来这确实是一个错误!

Turns out it was indeed a bug!

这篇关于在Kinetic.Line上检测鼠标事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆