Warning: The magic method EDD_Blocks::__wakeup() must have public visibility in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/edd-blocks-master/edd-blocks.php on line 101

Warning: The magic method EDD_Blocks::__wakeup() must have public visibility in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/edd-blocks/edd-blocks.php on line 101

Warning: The magic method GAINWP_Manager::__wakeup() must have public visibility in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/ga-in/gainwp.php on line 78

Deprecated: Optional parameter $filter declared before required parameter $metric is implicitly treated as a required parameter in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/ga-in/tools/gapi.php on line 555

Deprecated: Optional parameter $filter declared before required parameter $metric is implicitly treated as a required parameter in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/ga-in/tools/gapi.php on line 585

Deprecated: Optional parameter $filter declared before required parameter $metric is implicitly treated as a required parameter in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/ga-in/tools/gapi.php on line 617

Deprecated: Optional parameter $filter declared before required parameter $metric is implicitly treated as a required parameter in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/ga-in/tools/gapi.php on line 651

Deprecated: Optional parameter $filter declared before required parameter $metric is implicitly treated as a required parameter in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/ga-in/tools/gapi.php on line 686

Deprecated: Optional parameter $filter declared before required parameter $metric is implicitly treated as a required parameter in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/ga-in/tools/gapi.php on line 745

Deprecated: Optional parameter $filter declared before required parameter $metric is implicitly treated as a required parameter in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/ga-in/tools/gapi.php on line 785

Warning: Cannot modify header information - headers already sent by (output started at /home/wcc1969/public_html/phasergames.com/wp-content/plugins/edd-blocks-master/edd-blocks.php:101) in /home/wcc1969/public_html/phasergames.com/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/wcc1969/public_html/phasergames.com/wp-content/plugins/edd-blocks-master/edd-blocks.php:101) in /home/wcc1969/public_html/phasergames.com/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/wcc1969/public_html/phasergames.com/wp-content/plugins/edd-blocks-master/edd-blocks.php:101) in /home/wcc1969/public_html/phasergames.com/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/wcc1969/public_html/phasergames.com/wp-content/plugins/edd-blocks-master/edd-blocks.php:101) in /home/wcc1969/public_html/phasergames.com/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/wcc1969/public_html/phasergames.com/wp-content/plugins/edd-blocks-master/edd-blocks.php:101) in /home/wcc1969/public_html/phasergames.com/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/wcc1969/public_html/phasergames.com/wp-content/plugins/edd-blocks-master/edd-blocks.php:101) in /home/wcc1969/public_html/phasergames.com/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/wcc1969/public_html/phasergames.com/wp-content/plugins/edd-blocks-master/edd-blocks.php:101) in /home/wcc1969/public_html/phasergames.com/wp-includes/rest-api/class-wp-rest-server.php on line 1831

Warning: Cannot modify header information - headers already sent by (output started at /home/wcc1969/public_html/phasergames.com/wp-content/plugins/edd-blocks-master/edd-blocks.php:101) in /home/wcc1969/public_html/phasergames.com/wp-includes/rest-api/class-wp-rest-server.php on line 1831
{"id":25622,"date":"2021-05-11T15:15:32","date_gmt":"2021-05-11T08:15:32","guid":{"rendered":"https:\/\/phasergames.com\/?p=25622"},"modified":"2021-05-11T15:23:53","modified_gmt":"2021-05-11T08:23:53","slug":"loading-tilemaps-in-phaser-3-and-json","status":"publish","type":"post","link":"https:\/\/phasergames.com\/loading-tilemaps-in-phaser-3-and-json\/","title":{"rendered":"Loading TIleMaps in Phaser 3 and JSON"},"content":{"rendered":"\n

In my last post, I went over how to load tileMaps in phaser 3 using arrays<\/a>. It is a good method for loading small maps, but most game developers use tools like the Tiled <\/a>Map editor to create large maps. When we use tools like this, we need to load the map from a JSON file.<\/p>\n\n\n\n

I won’t go over how to use the software because it is fairly easy to use, but if you need help, there are tons of videos on it, including mine.<\/p>\n\n\n\n

Loading the JSON<\/h2>\n\n\n\n

There are two steps in preloading for the tileMaps. The first is to load the tiles themselves, the actual images. Place this code in your preload function.<\/p>\n\n\n\n

this.load.image(\"tiles\",\"src\/assets\/tiles.png\");<\/code><\/pre>\n\n\n\n

The next step is to load the JSON file. This contains all the information assembled by the software of positioning and layering.<\/p>\n\n\n\n

this.load.tilemapTiledJSON('map',\"src\/assets\/map1.json\");<\/code><\/pre>\n\n\n\n

Making the map<\/h2>\n\n\n\n

Next we need to make a map object to hold everything. The key is the preload cache key that was set in the code above. The tileWidth and tileHeight must be specified. <\/p>\n\n\n\n

 const map = this.make.tilemap({ key: \"map\", tileWidth: 64, tileHeight: 64});<\/code><\/pre>\n\n\n\n

Next make a tileset object with the key we used to load the images. This will break the spritesheet into an array of images for the map to use.<\/p>\n\n\n\n

 const tileset = map.addTilesetImage(\"tiles1\",\"tiles\");<\/code><\/pre>\n\n\n\n

The last step is to make a layer. The layer name can be found in the tileSet program in the LAYERS pane. You will need to make this code for every layer of the map you want to add to the game. <\/p>\n\n\n\n

Different layers can be useful for organization and for setting depth or collisions. Examples might be a layer of treasure or a layer of clouds. My next post will cover layers in more detail.<\/p>\n\n\n\n

const layer = map.createLayer(\"toplayer\", tileset, 0, 0);<\/code><\/pre>\n\n\n\n

Here is the entire code:<\/p>\n\n\n\n

export class SceneMain extends Phaser.Scene {\n    constructor() {\n        super(\"SceneMain\");\n    }\n    preload() {\n      this.load.image(\"tiles\",\"src\/assets\/tiles.png\");\n      this.load.tilemapTiledJSON('map',\"src\/assets\/map1.json\");\n    }\n    create() {        \n\n      \n        const map = this.make.tilemap({ key: \"map\", tileWidth: 64, tileHeight: 64});\n        const tileset = map.addTilesetImage(\"tiles1\",\"tiles\");\n        const layer = map.createLayer(\"toplayer\", tileset, 0, 0);\n        \n    }\n    update() {\n\n    }\n}\nexport default SceneMain;<\/code><\/pre>\n\n\n\t
\n\n\t\t\n\t\t
\n\t\t\t