geckosio / phaser-on-nodejs

Allows you to run Phaser 3 game (including Phaser's physics engines) on Node.js
MIT License
102 stars 11 forks source link

Not working using example in README #8

Closed tamagokun closed 3 years ago

tamagokun commented 3 years ago

I set up a small project to test this out, simply using the example code in the README:

require('@geckos.io/phaser-on-nodejs')
const Phaser = require('phaser')

// set the fps you need
const FPS = 30
global.phaserOnNodeFPS = FPS // default is 60

// your MainScene
class MainScene extends Phaser.Scene {
  constructor() {
    super('MainScene')
  }
  create() {
    console.log('it works!')
  }
}

// prepare the config for Phaser
const config = {
  type: Phaser.HEADLESS,
  width: 1280,
  height: 720,
  banner: false,
  audio: false,
  scene: [MainScene],
  fps: {
    target: FPS
  },
  physics: {
    default: 'arcade',
    arcade: {
      gravity: { y: 300 }
    }
  }
}

// start the game
new Phaser.Game(config)

I run it with node index.js and it exits immediately. I figured maybe it was just the process didn't have anything to "wait" for and ended before the scene could be created, so I created an http server and have the server listening at the end of the file so the process doesn't exit. However, still nothing. Not seeing the console.log from the scene's create method.

I am using Phaser 3.52.0 and node 14.5.0

yandeu commented 3 years ago

Phaser >= 3.50.0 does not work on the server yet.

See: https://github.com/geckosio/phaser-on-nodejs/issues/7

tamagokun commented 3 years ago

ah, it looked that bug had been fixed, thanks for clarifying. Older version worked great.