Newer
Older
pixi.js / src / interaction / interactiveTarget.js
@mathew groves mathew groves on 2 Feb 2015 1 KB New Interactive manager!
var core = require('../core');

var tempPoint = new core.math.Point();

core.DisplayObject.prototype.interactive = false;
core.DisplayObject.prototype.buttomMode = false;
core.DisplayObject.prototype.defaultCursor = 'pointer';

core.Sprite.prototype.hitTest = function( point )
{
    this.worldTransform.applyInverse(point,  tempPoint);

    var width = this._texture._frame.width;
    var height = this._texture._frame.height;
    var x1 = -width * this.anchor.x;
    var y1;

    if (tempPoint.x > x1 && tempPoint.x < x1 + width)
    {
        y1 = -height * this.anchor.y;

        if (tempPoint.y > y1 && tempPoint.y < y1 + height)
        {
            return true;
        }
    }

    return false;
}


core.Graphics.prototype.hitTest = function( point )
{
    this.worldTransform.applyInverse(point,  tempPoint);

    var graphicsData = this.graphicsData;

    for (i = 0; i < graphicsData.length; i++)
    {
        var data = graphicsData[i];

        if (!data.fill)
        {
            continue;
        }

        // only deal with fills..
        if (data.shape)
        {
            if (data.shape.contains(x, y))
            {
                return true;
            }
        }
    }

    return false;
}

module.exports = {};