Jump to content

over write input pointer x/y postion


ptotheaul
 Share

Recommended Posts

Is there a way to pass in an input pointer x/y values instead of having it use the mouse/tap location?  What I want to do with this is at a certain time check a point against a sprite using:

this.sprite.input.pointerOver()

but I want to be able to define the input point that's being checked.

In the end what I'm trying to do is record a tap event and then later in time(about 2 seconds) check if the tap event is over the sprite.  After the initial tap the input position might move or be lifted but I still want to check against the initial tap position.

Link to comment
Share on other sites

I've decided to just try and modify the pixel collision function from the Phaser source to try and occomplish what I described in the first post.  Here is the general function that I"m modifying.

 

I've changed the general sprite to the sprite I'm checking against 'Badguy'. 

Can someone explain what 'this.game.input' would be if I'm not using input and just want to check the point(x,y) passed in against the sprite 'Badguy'?

 

 

checkBadGuyHitPixel: function (x, y) {


        //  Grab a pixel from our image into the hitCanvas and then test it
        if (this.Badguy.texture.baseTexture.source)
        {
          
            var pixelPerfectAlpha = 255;

            this.game.input.hitContext.clearRect(0, 0, 1, 1);

            x += this.kaiju.texture.frame.x;
            y += this.kaiju.texture.frame.y;

            this.game.input.hitContext.drawImage(this.Badguy.texture.baseTexture.source, x, y, 1, 1, 0, 0, 1, 1);
            
            var rgb = this.game.input.hitContext.getImageData(0, 0, 1, 1);

            if (rgb.data[3] >= pixelPerfectAlpha)
            {
                return true;
            }
        }

        return false;

    },

 

Link to comment
Share on other sites

hitContext is the 2d context of the Input Manager's dedicated hit-detection canvas.

You could create your own, something like this:

this.hitCanvas = Phaser.CanvasPool.create(this, this.texture.frame.width, this.texture.frame.height);
this.hitContext = hitCanvas.getContext('2d');

// …

// shutdown:
Phaser.CanvasPool.removeByCanvas(this.hitCanvas);
this.hitCanvas = null;
this.hitContext = null;

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...