hondacalibra Posted February 3, 2017 Share Posted February 3, 2017 Hi! I am making an pokemon style mmo, and I've been struggling with this feature. I have a tilemap which is called map1.json When you move to a specific coordinate, I want my player to go over to another tilemap called map2.json Is this possible? My code (most is taken from a phaser example) var game = new Phaser.Game(1200, 800, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); function preload() { game.load.tilemap('desert', '/maps/map1.json', null, Phaser.Tilemap.TILED_JSON); game.load.image('tiles', '/img/tmw_desert_spacing.png'); game.load.image('car', '/img/car90.png'); } var map; var map2; var layer; var cursors; var sprite; function create() { game.physics.startSystem(Phaser.Physics.ARCADE); map = game.add.tilemap('desert'); map.addTilesetImage('Desert', 'tiles'); layer = map.createLayer('Ground'); layer.resizeWorld(); sprite = game.add.sprite(450, 80, 'car'); sprite.anchor.setTo(0.5, 0.5); game.physics.enable(sprite); cursors = game.input.keyboard.createCursorKeys(); } function update() { //movement sprite.body.velocity.x = 0; sprite.body.velocity.y = 0; sprite.body.angularVelocity = 0; if (cursors.left.isDown) { sprite.body.velocity.x = -200; } else if (cursors.right.isDown) { sprite.body.velocity.x = 200; } if (cursors.up.isDown) { sprite.body.velocity.y = -200; } if (cursors.down.isDown) { sprite.body.velocity.y = 200; } //collision detection if (sprite.body.x <= 0){ sprite.body.x = 0; } if (sprite.body.y <= 0){ sprite.body.y = 0; } if (sprite.body.x >= game.width - 30) { sprite.body.x = game.width - 30; } if (sprite.body.y >= game.height - 30) { sprite.body.y = game.height - 30; } } function render() { game.debug.text('Tile X: ' + layer.getTileX(sprite.x), 32, 48, 'rgb(0,0,0)'); game.debug.text('Tile Y: ' + layer.getTileY(sprite.y), 32, 64, 'rgb(0,0,0)'); } Link to comment Share on other sites More sharing options...
hondacalibra Posted February 3, 2017 Author Share Posted February 3, 2017 Please help with this, I need it to continue with my game Link to comment Share on other sites More sharing options...
hondacalibra Posted February 4, 2017 Author Share Posted February 4, 2017 okay found out how to do it. Link to comment Share on other sites More sharing options...
hexus Posted February 5, 2017 Share Posted February 5, 2017 Feel free to share how you solved the problem, in case anyone else wants to know the same thing. Link to comment Share on other sites More sharing options...
hondacalibra Posted February 6, 2017 Author Share Posted February 6, 2017 17 hours ago, hexus said: Feel free to share how you solved the problem, in case anyone else wants to know the same thing. I forgot to add z-index. Link to comment Share on other sites More sharing options...
Recommended Posts