DazZ Posted September 28, 2014 Share Posted September 28, 2014 When my player dies, he gets respawned to an x,y location that seems to be what the camera is currently showing rather than the maps x,y. If the camera hasn't moved the player spawns in the correct spot, otherwise he'll be a a few hundred pixels from where it died. However I have fixed this by loading a tilemap which is the size of the screen and then restarting the frame like so.Player.prototype.death = function(){ //Set map and world size to camera size to fix respawning in wrong place map = game.add.tilemap('menuMap'); platforms = map.createLayer('platforms'); platforms.resizeWorld(); game.state.restart();};menuMap is 800,600 the same as the camera whilst the level maps are a bit larger, but setting the world to 800,600 and then restarting fixes my spawn issue. Obviously this is rather hacky and I feel I'm missing something that should make this cleaner. Any insight would be lovely! Edit: I've narrowed it down to setting the world boundaries to nothing instead of loading another map, but I still feel like I'm doing something wrong.Player.prototype.death = function(){ game.world.setBounds(0, 0, 0, 0); //fixes spawning in wrong place game.state.restart();}; Link to comment Share on other sites More sharing options...
lewster32 Posted September 29, 2014 Share Posted September 29, 2014 Not sure if this is the solution to the problem or not but changing the state does not reset the world bounds, so I think if you explicitly set the world bounds to whatever size they need to be at the start of each state (and for states which do not have specific requirements, set the bounds to the size of the game, which is the default) things should hopefully work as expected. Link to comment Share on other sites More sharing options...
DazZ Posted September 29, 2014 Author Share Posted September 29, 2014 I think if you explicitly set the world bounds to whatever size they need to be at the start of each state (and for states which do not have specific requirements, set the bounds to the size of the game, which is the default) things should hopefully work as expected. In the create function for every state I have platforms.resizeWorld(); which I think should be doing just that.It is called before putting the player in game as well. Link to comment Share on other sites More sharing options...
Recommended Posts