Resolves issue with pixel perfect click / over detection on Sprites that used trimmed image atlases for animations or frames > 0.

This commit is contained in:
photonstorm 2014-08-01 17:46:39 +01:00
parent 48869776f2
commit aabdf6f97a
2 changed files with 21 additions and 2 deletions

View file

@ -58,6 +58,9 @@ Version 2.1.0 - "Cairhien" - -in development-
* Remove escaping backslashes from RetroFont text set documentation (thanks @jackrugile #1051)
* Phaser.Loader was incorrectly getting the responseText from _xhr instead of _ajax on IE9 xDomainRequests (thanks @lardratboy #1050)
* Phaser.Physics.P2.addPolygon now takes a nested array again (thanks @wayfu #1060)
* Fix for previous PR #1028 where the P2.setBoundsToWorld call was overriding setBoundsToWorld in the P2 constructor (thanks @Dumtard #1028)
* Fix for scale issues in CocoonJS using webgl renderer and screencanvas (thanks @txusinho #1064)
* Resolves issue with pixel perfect click / over detection on Sprites that used trimmed image atlases for animations or frames > 0.
### Migration Guide

View file

@ -718,8 +718,6 @@ Phaser.InputHandler.prototype = {
// Grab a pixel from our image into the hitCanvas and then test it
if (this.sprite.texture.baseTexture.source)
{
this.game.input.hitContext.clearRect(0, 0, 1, 1);
if (x === null && y === null)
{
// Use the pointer parameter
@ -742,6 +740,24 @@ Phaser.InputHandler.prototype = {
x += this.sprite.texture.frame.x;
y += this.sprite.texture.frame.y;
if (this.sprite.texture.trim)
{
x -= this.sprite.texture.trim.x;
y -= this.sprite.texture.trim.y;
// If the coordinates are outside the trim area we return false immediately, to save doing a draw call
if (x < this.sprite.texture.crop.x || x > this.sprite.texture.crop.right || y < this.sprite.texture.crop.y || y > this.sprite.texture.crop.bottom)
{
this._dx = x;
this._dy = y;
return false;
}
}
this._dx = x;
this._dy = y;
this.game.input.hitContext.clearRect(0, 0, 1, 1);
this.game.input.hitContext.drawImage(this.sprite.texture.baseTexture.source, x, y, 1, 1, 0, 0, 1, 1);
var rgb = this.game.input.hitContext.getImageData(0, 0, 1, 1);