geckosio / phaser-on-nodejs

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

Loading collision maps #1

Closed davidmball closed 4 years ago

davidmball commented 5 years ago

Thanks for your work on getting phaser to run within nodejs on a server.

I'm trying to load a tilemap for collision detection on the server using node.js. However, I think this isn't working because loading assets on the server isn't supported. When I call this.load.tilemapTiledJSON('map', 'assets/tileset-collision-shapes.json'); in preload() I get Error: Uncaught [TypeError: s.open is not a function]. I guess either (a) I'm making a mistake, (b) the server needs a way to use the existing phaser io calls to load these assets or (c) add another way to load them directly into the physics engine (matter in my case). (b) Seems the best to me as long as the server still doesn't try and render anything. Thoughts?

yandeu commented 5 years ago

Sorry for the delay. I was offline quite a while :/

I have never used a collision map. I guess the json contains the body size and offset and the url to its image?

I also guess if you use the function tilemapTiledJSON phaser tries automatically to load the assets which, I guess, will not work on the server.

I can't tell you for sure if this will work, but try to find the function that loads the assets in phaser and overwrite it with a anonymous function like this:

Phaser.something.theFunctionWhichLoadsTheAssets = () => {}

You could of course also give me access to the repo or create a simple sample and I will take a look. Hopefully we can solve this :)

davidmball commented 5 years ago

Hi! I now suspect this is a general issue about loading files on the server rather than specific to maps. The easiest way to cause the error is any load in the preload() eg

preload ()
{
    this.load.image('player', 'assets/images/phaser-ship.png');
}

I'm guessing there will need to be something to implement the open function for headless mode on the server.

yandeu commented 5 years ago

I guess the headless mode of Phaser is not really designed to be used on node.js. Maybe a new "node" mode should be implemented.

Anyway, have you figured out a way to do it?

davidmball commented 5 years ago

I haven't work this one out yet. At the moment I am just storing the data in the js files which is working for the moment but won't be very scalable. Somehow files are loaded from the server, eg using the require statements.