hondacalibra Posted January 28, 2017 Share Posted January 28, 2017 Hi I'm using tilemaps and i've been looking for a way to go to another map when x is less than 0. i've tried so many things but I just can't figure it out. Here is my full code: 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/desert.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...
Recommended Posts