Giter Club home page Giter Club logo

phaser-plugin-game-scale's Introduction

Phaser 3 Game Scale Plugin

Scale or resize the game canvas. Demo

This is for Phaser v3.15 (or earlier) only. Since Phaser 3.16 use the Scale Manager instead.

Modes

  • fit — scale the canvas up or down to fit the container, and within min/max lengths (if set).
  • resize — change the game dimensions to fit the container, and within min/max lengths (if set).
  • resize-and-fit — resize within min/max lengths, then scale the canvas to fit any remaining space within the container.
  • none — set the canvas scale to 100%.

The default mode is fit.

Use

new Phaser.Game({
  // ...
  plugins: {
    global: [{
      key: 'GameScalePlugin',
      plugin: Phaser.Plugins.GameScalePlugin,
      mapping: 'gameScale',
      data: {/* See 'Configuration' */}
    }]
  }
  // ...
});

If you're using ES6 modules, you can use the default export instead:

import GameScalePlugin from 'phaser-plugin-game-scale';

new Phaser.Game({
  // ...
  plugins: {
    global: [{
      key: 'GameScalePlugin',
      plugin: GameScalePlugin,
      mapping: 'gameScale',
      data: {/* See 'Configuration' */}
    }]
  }
  // ...
});

Set the scale mode:

// Within a scene:
this.gameScale.setMode('resize');

Listen to a scene's resize event to react to game size changes.

See the examples for details.

Configuration

These are the default settings:

{
  debounce: false,
  debounceDelay: 50,   // Debounce interval, in ms
  maxHeight: Infinity,
  maxWidth: Infinity,
  minHeight: 0,
  minWidth: 0,
  mode: 'fit',
  resizeCameras: true, // Resize each scene camera when resizing the game
  snap: null,          // Snap interval, in px
}
// Within a scene:
this.gameScale.configure({/* … */});

phaser-plugin-game-scale's People

Contributors

dependabot[bot] avatar samme avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

phaser-plugin-game-scale's Issues

this.game.resize seems broken in phaser 3.16.2

Hi, samme! first of all, thank you for making this awesome plugin :)

The plugin was working very well until I update phaser to 3.16.2. It is showing error in GameScenePlugin.js on line this.game.resize(width, height);

In new phaser resize function has been removed & we need to use scale manager resize function instead. I try to update it with same and resolved the error but now the game is not getting resized.

can you please look into this?

Thank you.

Webpack compatibility

Thank you for making this.

I am having issue getting this to work with webpack. I'm importing like this:

import 'phaser';
import ControlPlugin from './plugins/control';
import GameScalePlugin from './plugins/GameScalePlugin';
import BootScene from './scenes/BootScene'
import PreloadScene from './scenes/PreloadScene'
import StageScene from './scenes/StageScene'

const config = {
	type: Phaser.AUTO,
	parent: 'wrapper',
	width: 800,
	height: 600,
	scaleMode: 0,
	pixelArt: true,
	clearBeforeRender: false,
	physics: {
		default: 'matter',
		matter: {
			gravity: { y: 1 },
			debug: false,
			enableSleep: false
		}
	},
	plugins: {
		scene: [
			{ key: 'ControlPlugin', plugin: ControlPlugin, mapping: 'Controls' }
		],
		global: [
			{ key: 'GameScalePlugin', plugin: GameScalePlugin, mapping: 'gameScale' }
		]
	},
	scene: [
		BootScene,
		PreloadScene,
		StageScene
	]
};

const game = new Phaser.Game(config);

I can see the plugin in the bundle but it isn't getting mapped to the scenes.

Resize and fit seems buggy in the examples

I expect the canvas to always be 100%, sometimes after vigorous resizing, the canvas gets stuck in a smaller size.

image

Also, the fit part doesn't seem to scale game objects in resize-and-fit. It centers but no resize.

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.