Jump to content

Passing object states / flags between maps & states


Recommended Posts

I'm working learning game development using Phaser.  I made a simple topdown game, and now am trying to extend what I learned into a more complex game.


Right now, I have a game with 2 maps.  On the first map, there's a locked door.  When you pick up the key, it unlocks to the door, and you can go through it to the second map.  If you walk back up the stairs from map2, you are returned to map1.  The problem is, none of the object states are saved, so the door returns to being locked.


You can see what I'm talking about here: http://kyle.pink/games/topdown2/ (with increased movement speed for your convenience!).


The map logic is as follows:

changeMap: function(player, door) {	if(!door.open) {		return;	}	this.game.state.start('Game', true, false, door);}

Where door looks like this:

"name":"TrapDoor1", "properties":    {     "doorID":"1",     "open":"false",     "sprite":"closedTrapdoor",     "targetTilemap":"map2",     "targetX":"256",     "targetY":"192",     "type":"door"    },

Which is loaded like this: 

init: function(mapData) {	this.mapData = mapData;	this.targetX = parseInt(mapData.targetX) || 32;	this.targetY = parseInt(mapData.targetY) || 32;	this.mapToLoad = mapData.targetTilemap;},create: function() {	this.map = this.game.add.tilemap(this.mapToLoad)

You can browse the full code here: https://github.com/Pink401k/topdown2


The only thing I can think of doing is passing the map objects between states.  But, that seems REALLY unwieldily and unperformant, especially when there are many maps and objects.  If anyone has some pointers or examples / articles to look at, I'd really appreciate it.


Thanks in advanced for any help. 

Link to comment
Share on other sites


  • Recently Browsing   0 members

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