Nepoxx Posted September 15, 2014 Share Posted September 15, 2014 Hey everyone, as explained in another thread I started, I'm trying to "move the world" instead of moving the player. For that purpose I want to make a tilemap scroll, but I'm not able to. I tried setting TilemapLayer.scrollX and TilemapLayer.scrollY and nothing happened. I even tried something like TilemapLayer.scrollX = player.x * 2; to no avail. How are you supposed to use those functions? /* Game logic */function create() { game.time.advancedTiming = true; game.physics.startSystem(Phaser.Physics.ARCADE); game.stage.backgroundColor = '#000000'; /* Map definition */ map = game.add.tilemap('map'); map.addTilesetImage('magecity', undefined, undefined, undefined, undefined, undefined, 1); map.setCollisionByExclusion([73, 74, 75, 81, 82, 83, 89, 90, 91]); ground = map.createLayer(0); ground.debug = true; ground.resizeWorld(); // Player sprite player = game.add.sprite(game.width, game.height, 'player'); game.physics.enable(player, Phaser.Physics.ARCADE); player.body.collideWorldBounds = true; player.anchor.setTo(0.5, 0.5); game.camera.follow(player); HUD = new HeadUpDisplay(game, 'Head up display'); //cursors = game.input.keyboard.createCursorKeys(); upKey = game.input.keyboard.addKey(Phaser.Keyboard.W); downKey = game.input.keyboard.addKey(Phaser.Keyboard.S); leftKey = game.input.keyboard.addKey(Phaser.Keyboard.A); rightKey = game.input.keyboard.addKey(Phaser.Keyboard.D); socket = io.connect('http://poste-0432', { port: 8000, transports: ['websocket'] }); setSocketEventHandlers();}function update() { game.physics.arcade.collide(player, ground); ground.scrollX = 5; //does nothing ground.scrollX = player.x * 2; //nothing if (player.y < 10) { player.x = game.width / 2; player.y = game.height / 2; } if (player.body.deltaX() !== 0 || player.body.deltaY() !== 0) { socket.emit('update player', { x: player.x, y: player.y }); } player.body.velocity.x = 0; player.body.velocity.y = 0; if (leftKey.isDown) { player.body.velocity.x = -150; } else if (rightKey.isDown) { player.body.velocity.x = 150; } if (upKey.isDown) { player.body.velocity.y = -150; } else if (downKey.isDown) { player.body.velocity.y = 150; } player.rotation = game.physics.arcade.angleToPointer(player) + 1.57;}var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update}); Link to comment Share on other sites More sharing options...
locohost Posted November 10, 2014 Share Posted November 10, 2014 Did you ever resolve this? Use game.camera.follow(yourPlayerObject, Phaser.Camera.FOLLOW_TOPDOWN); Link to comment Share on other sites More sharing options...
ozankasikci Posted March 29, 2015 Share Posted March 29, 2015 Hi, i'm also having problem with scrolling tilemap layer, can please someone explain how it can be done ? Link to comment Share on other sites More sharing options...
Recommended Posts