mirror of
https://github.com/photonstorm/phaser
synced 2024-11-26 14:40:38 +00:00
Added Game.isOver and mouseover and mouseout events.
This commit is contained in:
parent
c24f3b8fdb
commit
e6e33f5e21
3 changed files with 29 additions and 0 deletions
|
@ -123,6 +123,9 @@ TODO - Out of Canvas events
|
|||
* `CameraManager.fromJSON` will now set the visible property is defined in the config.
|
||||
* `ScenePlugin.run` is a new method that will run the given Scene and not change the state of the current Scene at all. If the scene is asleep, it will be woken. If it's paused, it will be resumed. If not running at all, it will be started.
|
||||
* `TextureManager.getPixelAlpha` is a new method that will return the alpha value of a pixel from the given texture and frame. It will return `null` if the coordinates were out of bounds, otherwise a value between 0 and 255.
|
||||
* `Game.isOver` is a new read-only boolean property that indicates if the mouse pointer is currently over the game canvas or not. It is set by the VisibilityHandler and is only reliable on desktop systems.
|
||||
* A new event `Game.mouseout` is dispatched if the mouse leaves the game canvas. You can listen to it from `this.sys.game.events.on('mouseout')` from within a Scene.
|
||||
* A new event `Game.mouseover` is dispatched if the mouse enters the game canvas, having previously been outside of it. You can listen to it from `this.sys.game.events.on('mouseover')` from within a Scene.
|
||||
|
||||
### Updates
|
||||
|
||||
|
|
|
@ -263,6 +263,17 @@ var Game = new Class({
|
|||
*/
|
||||
this.hasFocus = false;
|
||||
|
||||
/**
|
||||
* Is the mouse pointer currently over the game canvas or not?
|
||||
* This is modified by the VisibilityHandler.
|
||||
*
|
||||
* @name Phaser.Game#isOver
|
||||
* @type {boolean}
|
||||
* @readOnly
|
||||
* @since 3.10.0
|
||||
*/
|
||||
this.isOver = true;
|
||||
|
||||
// Wait for the DOM Ready event, then call boot.
|
||||
DOMContentLoaded(this.boot.bind(this));
|
||||
},
|
||||
|
|
|
@ -115,6 +115,21 @@ var VisibilityHandler = function (game)
|
|||
window.focus();
|
||||
}, { passive: true });
|
||||
}
|
||||
|
||||
if (game.canvas)
|
||||
{
|
||||
game.canvas.onmouseout = function ()
|
||||
{
|
||||
game.isOver = false;
|
||||
eventEmitter.emit('mouseout');
|
||||
};
|
||||
|
||||
game.canvas.onmouseover = function ()
|
||||
{
|
||||
game.isOver = true;
|
||||
eventEmitter.emit('mouseover');
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = VisibilityHandler;
|
||||
|
|
Loading…
Reference in a new issue