【问题标题】:Kineticjs: Image Stoke is not available when using hit regionKineticjs:使用命中区域时图像斯托克不可用
【发布时间】:2014-04-13 22:57:18
【问题描述】:

我使用 Kineticjs 命中区域,位于:http://www.html5canvastutorials.com/kineticjs/html5-canvas-pixel-detection-with-kineticjs/

我的图片有中风:

var lion = new Kinetic.Image({
          image: images.lion,
          x: 280,
          y: 30,
          stroke: "red" 
        });

图像在不使用命中区域时有笔触,但当我使用以下区域时,我没有看到任何笔触。

    // in order to ignore transparent pixels in an image when detecting
    // events, we first need to cache the image
    lion.cache();

    // next, we need to redraw the hit graph using the cached image
    lion.drawHitFromCache();

    // finally, we need to redraw the layer hit graph
    layer.drawHit();

如何在使用点击区域时让图像的笔触可见?

【问题讨论】:

    标签: javascript html canvas kineticjs


    【解决方案1】:

    如果你想要描边边框,可以将 drawBorder 属性设置为 true:

    lion.cache({
        drawBorder: true
    });
    

    干杯!

    【讨论】:

    • 文档说这是“出于调试目的”,这真的是要走的路吗?
    • 文档说“缓存一个节点并在边界框周围画一个红色边框”
    • 我想这取决于您的设计需求。 drawBorder 是一个很好的荧光笔,但如果您需要更灵活的东西,您可以创建一个带有笔触矩形的组,其中包含您的图像。
    • 我是 kineticjs 新手。可以发个例子吗?
    • KineticJS 必须在图层对象内画布。您在页面上看到的一个画布,另一个不可见,但用于命中检测(用于任何指针事件)。因此,您可以使用drawScene 函数仅更新可见的“场景”画布,或者仅使用drawHit 更新画布,或仅使用draw 两者兼而有之。
    猜你喜欢
    • 1970-01-01
    • 2013-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-02
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    相关资源
    最近更新 更多