Jump to content

Loading a new tilemap while the game is already running?


What?
 Share

Recommended Posts

In my game I want a single tilemap loaded for each room as the player enters them. I made a function that loads a tilemap, where the name of it is the parameter:

new_room: function(name)	{		this.load.tilemap(name, 'assets/tile/' + name + '.json', null, Phaser.Tilemap.TILED_JSON);		map = this.game.add.tilemap(name);				foreground = map.createLayer('foreground');		map.setCollisionBetween(1, 100000, true, 'foreground');	},

The name of the tilemap I'm trying to load is "second", but it's not working:

"Phaser.Cache.getTilemapData: Invalid key: "second"" phaser.min.js:16"Phaser.TilemapParser.parse - No map data found for key second" phaser.min.js:20

I feel like there could be some feature in Phaser that does what I'm trying to do. I'm not familiar with dynamically loading things.

Link to comment
Share on other sites

  • 1 year later...
49 minutes ago, Ashish said:

Hi . I am getting the same error . Can you tell me that how you solved this problem?

 

I think the problem was that I was trying to add the tilemap before it finished loading. The solution was using the "onLoadComplete" event to add the tilemap after it was loaded in. You also need to start the loading with "load.start()" to make it load in the first place.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...