mirror of
https://github.com/wassname/phaser.git
synced 2026-09-09 11:28:47 +08:00
ScaleManager has 2 new events: ScaleManager.enterFullScreen and ScaleManager.leaveFullScreen, so you can respond to fullscreen changes directly.
Fullscreen mode now uses window.outerWidth/Height when using EXACT_FIT as the scale mode, which fixes input coordinate errors (fixes #232)
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('dragon', 'assets/pics/cougar_dragonsun.png');
|
||||
game.load.spritesheet('button', 'assets/buttons/button_sprite_sheet.png', 193, 71);
|
||||
|
||||
}
|
||||
|
||||
var button;
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'dragon');
|
||||
sprite.anchor.set(0.5);
|
||||
|
||||
game.stage.backgroundColor = '#000';
|
||||
|
||||
// Stretch to fill
|
||||
game.scale.fullScreenScaleMode = Phaser.ScaleManager.EXACT_FIT;
|
||||
|
||||
// Keep original size
|
||||
// game.scale.fullScreenScaleMode = Phaser.ScaleManager.NO_SCALE;
|
||||
|
||||
// Maintain aspect ratio
|
||||
// game.scale.fullScreenScaleMode = Phaser.ScaleManager.SHOW_ALL;
|
||||
|
||||
button = game.add.button(game.world.centerX - 95, 500, 'button', actionOnClick, this, 2, 1, 0);
|
||||
button.visible = false;
|
||||
|
||||
game.scale.enterFullScreen.add(onEnterFullScreen, this);
|
||||
game.scale.leaveFullScreen.add(onLeaveFullScreen, this);
|
||||
|
||||
game.input.onDown.add(gofull, this);
|
||||
|
||||
}
|
||||
|
||||
function onEnterFullScreen() {
|
||||
|
||||
button.visible = true;
|
||||
|
||||
}
|
||||
|
||||
function onLeaveFullScreen() {
|
||||
|
||||
button.visible = false;
|
||||
|
||||
}
|
||||
|
||||
function gofull() {
|
||||
|
||||
game.scale.startFullScreen();
|
||||
|
||||
}
|
||||
|
||||
function actionOnClick () {
|
||||
|
||||
sprite.tint = Math.random() * 0xFFFFFF;
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
}
|
||||
|
||||
function render () {
|
||||
|
||||
if (game.scale.isFullScreen)
|
||||
{
|
||||
game.debug.renderText('ESC to leave fullscreen', 270, 16);
|
||||
}
|
||||
else
|
||||
{
|
||||
game.debug.renderText('Click / Tap to go fullscreen', 270, 16);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,12 +4,16 @@ var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload:
|
||||
function preload() {
|
||||
|
||||
game.load.image('dragon', 'assets/pics/cougar_dragonsun.png');
|
||||
game.load.spritesheet('button', 'assets/buttons/button_sprite_sheet.png', 193, 71);
|
||||
|
||||
}
|
||||
|
||||
var button;
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
var sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'dragon');
|
||||
sprite = game.add.sprite(game.world.centerX, game.world.centerY, 'dragon');
|
||||
sprite.anchor.set(0.5);
|
||||
|
||||
game.stage.backgroundColor = '#000';
|
||||
@@ -23,22 +27,53 @@ function create() {
|
||||
// Maintain aspect ratio
|
||||
// game.scale.fullScreenScaleMode = Phaser.ScaleManager.SHOW_ALL;
|
||||
|
||||
button = game.add.button(game.world.centerX - 95, 500, 'button', actionOnClick, this, 2, 1, 0);
|
||||
button.visible = false;
|
||||
|
||||
game.scale.enterFullScreen.add(onEnterFullScreen, this);
|
||||
game.scale.leaveFullScreen.add(onLeaveFullScreen, this);
|
||||
|
||||
game.input.onDown.add(gofull, this);
|
||||
|
||||
}
|
||||
|
||||
function onEnterFullScreen() {
|
||||
|
||||
button.visible = true;
|
||||
|
||||
}
|
||||
|
||||
function onLeaveFullScreen() {
|
||||
|
||||
button.visible = false;
|
||||
|
||||
}
|
||||
|
||||
function gofull() {
|
||||
|
||||
game.scale.startFullScreen();
|
||||
|
||||
}
|
||||
|
||||
function actionOnClick () {
|
||||
|
||||
sprite.tint = Math.random() * 0xFFFFFF;
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
}
|
||||
|
||||
function render () {
|
||||
|
||||
game.debug.renderText('Click / Tap to go fullscreen', 270, 16);
|
||||
if (game.scale.isFullScreen)
|
||||
{
|
||||
game.debug.renderText('ESC to leave fullscreen', 270, 16);
|
||||
}
|
||||
else
|
||||
{
|
||||
game.debug.renderText('Click / Tap to go fullscreen', 270, 16);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -92,6 +92,8 @@
|
||||
?>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-family: Arial;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user