Skip to content

Commit e6e33f5

Browse files
committed
Added Game.isOver and mouseover and mouseout events.
1 parent c24f3b8 commit e6e33f5

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ TODO - Out of Canvas events
123123
* `CameraManager.fromJSON` will now set the visible property is defined in the config.
124124
* `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.
125125
* `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.
126+
* `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.
127+
* 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.
128+
* 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.
126129

127130
### Updates
128131

src/boot/Game.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,17 @@ var Game = new Class({
263263
*/
264264
this.hasFocus = false;
265265

266+
/**
267+
* Is the mouse pointer currently over the game canvas or not?
268+
* This is modified by the VisibilityHandler.
269+
*
270+
* @name Phaser.Game#isOver
271+
* @type {boolean}
272+
* @readOnly
273+
* @since 3.10.0
274+
*/
275+
this.isOver = true;
276+
266277
// Wait for the DOM Ready event, then call boot.
267278
DOMContentLoaded(this.boot.bind(this));
268279
},

src/boot/VisibilityHandler.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,21 @@ var VisibilityHandler = function (game)
115115
window.focus();
116116
}, { passive: true });
117117
}
118+
119+
if (game.canvas)
120+
{
121+
game.canvas.onmouseout = function ()
122+
{
123+
game.isOver = false;
124+
eventEmitter.emit('mouseout');
125+
};
126+
127+
game.canvas.onmouseover = function ()
128+
{
129+
game.isOver = true;
130+
eventEmitter.emit('mouseover');
131+
};
132+
}
118133
};
119134

120135
module.exports = VisibilityHandler;

0 commit comments

Comments
 (0)