Closed GoodClover closed 4 years ago
This is a use case scenario I did not thought about.
I made small modifications to allow this. Please update pixelbox to 2.0.1
in your package.json
and reinstall.
You should then be able to do the following:
var TileMap = require("pixelbox/TileMap")
var rawMaps = fs.readFileSync(__dirname + "/client/assets/maps.json", "utf8")
var mapsJSON = JSON.parse(rawMaps)
TileMap.loadBank(mapsJSON)
var map = TileMap.getMap('map')
Please tell me if that resolve your issue.
The server appears to work now, I just had to ensure that the "sheet"
property was set to ""
in maps.json or it would error out trying to find the tilesheet as it isn't in the default location. This dosen't matter for me as the server doesn't need this tilesheet anyways.
I assume this is my code not working now but on the client I get this:
Uncaught TypeError: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The provided value is not of type '(CSSImageValue or HTMLImageElement or SVGImageElement or HTMLVideoElement or HTMLCanvasElement or ImageBitmap or OffscreenCanvas)'
at n.draw (index.js:1)
at window.draw (index.js:1)
at Object.i.update (index.js:1)
at t (index.js:1)
I'm not quite sure what causes this, but I guess it may be the tilesheet not being loaded?
The code is checking that the map isn't null
before attempting to draw it.
Will look into it more when I get time.
I have it working now have to add .copy()
in the server and .paste()
in the client as the TileMap looses its ability to work once sent to the client.
Hi, I'm creating a simple server with node.js and socket.io where there can be multiple players and they walk around. The TileMaps were stored client-side and I want them to be server side and they are sent to the player.
I've downloaded pixelbox on the server with npm bit it appears to export nothing and doing
var TileMap = require("./node_modules/pixelbox/TileMap")
doesn't appear to work either. Is there any way to use the TileMaps without creating a separate 'game' that hosts the server?My code is as follows:
also tried
maps[map.name] = new TileMap().load(map)
andmaps[map.name] = TileMap.load(map)
bit it appears to export nothingEdit: formatting