2018-06-08 16:50:47 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2022-02-28 14:29:51 +00:00
|
|
|
* @copyright 2022 Photon Storm Ltd.
|
2019-05-10 15:15:04 +00:00
|
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
2018-06-08 16:50:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2018-06-08 17:24:08 +00:00
|
|
|
* Creates a new Pixel Perfect Handler function.
|
2018-06-08 16:50:47 +00:00
|
|
|
*
|
2018-06-08 17:24:08 +00:00
|
|
|
* Access via `InputPlugin.makePixelPerfect` rather than calling it directly.
|
2018-06-08 16:50:47 +00:00
|
|
|
*
|
|
|
|
* @function Phaser.Input.CreatePixelPerfectHandler
|
|
|
|
* @since 3.10.0
|
|
|
|
*
|
2018-06-08 17:24:08 +00:00
|
|
|
* @param {Phaser.Textures.TextureManager} textureManager - A reference to the Texture Manager.
|
2020-11-23 10:22:13 +00:00
|
|
|
* @param {number} alphaTolerance - The alpha level that the pixel should be above to be included as a successful interaction.
|
2018-06-08 16:50:47 +00:00
|
|
|
*
|
2018-06-08 17:24:08 +00:00
|
|
|
* @return {function} The new Pixel Perfect Handler function.
|
2018-06-08 16:50:47 +00:00
|
|
|
*/
|
|
|
|
var CreatePixelPerfectHandler = function (textureManager, alphaTolerance)
|
|
|
|
{
|
|
|
|
return function (hitArea, x, y, gameObject)
|
|
|
|
{
|
2018-08-16 17:23:10 +00:00
|
|
|
var alpha = textureManager.getPixelAlpha(x, y, gameObject.texture.key, gameObject.frame.name);
|
2018-06-08 16:50:47 +00:00
|
|
|
|
2018-06-08 17:24:08 +00:00
|
|
|
return (alpha && alpha >= alphaTolerance);
|
2018-06-08 16:50:47 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = CreatePixelPerfectHandler;
|