Jump to content

resize event only gets called when the screen gets smaller


Recommended Posts

In order to create a fully responsive game, i´d like to listen to the resize event, but it only gets called when i resize the screen to smaller values. This is my code (well, part of it):

export default class MainState extends Phaser.State {
	constructor() {
	init() {
		this.scale.scaleMode = Phaser.ScaleManager.RESIZE;
	resize(width, height) {
		console.log(widht, height);

In the resize callback, i resize my game elements - they obviously get smaller when i make the screen smaller. But if i increase the size of the window again, the callback never gets called. Is there any workaround for this? Is this a known issue?

Link to comment
Share on other sites

The problem is elsewhere in your code / css, as this works fine no matter how it's scaled:

var game = new Phaser.Game("100%", "100%", Phaser.AUTO, '', { preload: preload, create: create, resize: resize });

function preload() {

    game.load.image('einstein', 'assets/pics/ra_einstein.png');


var sprite1;
var sprite2;

function create() {

    game.scale.scaleMode = Phaser.ScaleManager.RESIZE;

    sprite1 = game.add.sprite(0, 0, 'einstein');

    sprite2 = game.add.sprite(game.width, game.height, 'einstein');
    sprite2.anchor.set(1, 1);


function resize(width, height) {

    sprite2.x = width;
    sprite2.y = height;



Link to comment
Share on other sites

  • 2 weeks later...

you know what, it suddenly worked. i only changed some react stuff (my game runs on react and phaser) - using a single route now, with phaser only. i had several routes before, because my game will get pretty big with many states and i wanted to create webpack bundles for several code parts....but i may even remove react now, because now it´s pointless if i just load phaser...

anyway, react messed it up, not entirely sure why (because there was no additional content next to phaser). maybe someone knows what could go wrong, but i would consider this closed for me :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...