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

Cannot call tilemapTiledJSON #9

Closed tsafs closed 3 years ago

tsafs commented 3 years ago

Describe the bug On the server-side calling

this.load.tilemapTiledJSON('map', 'tilemaps/level1.json'); 

from a scene causes the following error:

/usr/app/node_modules/@geckos.io/phaser-on-nodejs/lib/fakeXMLHttpRequest.js:21
            throw err;
            ^

[Error: ENOENT: no such file or directory, open '/usr/app/node_modules/@geckos.io/phaser-on-nodejs/lib/tilemaps/level1.json'] {
      errno: -2,
      code: 'ENOENT',
      syscall: 'open',
      path: '/usr/app/node_modules/@geckos.io/phaser-on-nodejs/lib/tilemaps/level1.json'
}

Expectation

I expected the tilemap to be loaded relatively from the scene's path, i.e. from <project>/src/myGameScene.js

Have a question?

Is there any way to load tilemaps on the server-side? The examples show only examples for levels statically generated by code.

yandeu commented 3 years ago

Your path looks wrong. Try:

const path = require('path')
const fs = require('fs')

const pathToFile = path.join(path.resolve(), 'tilemaps/level1.json')
const exists = fs.existsSync(pathToFile)

console.log('Path: ', pathToFile)
console.log('DoesExist?: ', exists)
tsafs commented 3 years ago

Thank you!