Note that there are some explanatory texts on larger screens.

plurals
  1. POkineticjs - createImageRegion for pixels with opacity > 0 not only 1
    primarykey
    data
    text
    <p>So the createImageRegion method ignores all pixels with a tiny bit of alpha/opacity. </p> <p>How can you make this function so that also pixels with an opacity of .5 or something will be count for hitdetection?</p> <p>I looked into KineticJS. A colorKey is added to a hitregion, but it transforms the key to a hex key with no alpha. I can't figure out a way how i could make this work.</p> <p>Help is much appriciated!</p> <p>this is where the magic happens. But i don't understand how i can include pixels whith any kind of transpanacy but 0</p> <pre><code>createImageHitRegion: function (callback) { var canvas = new Kinetic.Canvas(this.attrs.width, this.attrs.height); var context = canvas.getContext(); context.drawImage(this.attrs.image, 0, 0); try { var imageData = context.getImageData(0, 0, canvas.getWidth(), canvas.getHeight()); var data = imageData.data; var rgbColorKey = Kinetic.Type._hexToRgb(this.colorKey); // replace non transparent pixels with color key for (var i = 0, n = data.length; i &lt; n; i += 4) { data[i] = rgbColorKey.r; data[i + 1] = rgbColorKey.g; data[i + 2] = rgbColorKey.b; // i+3 is alpha (the fourth element) } var that = this; Kinetic.Type._getImage(imageData, function (imageObj) { that.imageHitRegion = imageObj; if (callback) { callback(); } }); } catch (e) { Kinetic.Global.warn('Unable to create image hit region. ' + e.message); } } </code></pre> <p>When i include: data[i + 3] = 255 (rgbColorKey.a) does not excist, none of the imageevents are working anymore</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload