Foxhunt Posted February 15, 2015 Share Posted February 15, 2015 Hi, i'm trying to build a up scrolling platformer and have issues getting the camera to follow my player sprite. I set the world width and height to 800x480 set the world bounds to 0, -200, 1600, 480.When doing this the Camera starts at x:0, y:200 and follows the player along the x-axis but wont move down the y-axis towards the player. See here Code that is involved: //dimensions game.world.setBounds(0, -200, 1600, 480); //Physics ON!! game.physics.startSystem(Phaser.Physics.ARCADE); //adding Background game.stage.backgroundColor = '#000'; //Create and configure platforms a Group platforms = game.add.group(); platforms.enableBody = true; //adding ground var Ground = platforms.create(0, game.world.height - 130, 'Bar'); var ledge1 = platforms.create(500, Ground.y - 30 - 45, 'Bar'); var ledge2 = platforms.create(-500, Ground.y - 30 - 45, 'Bar'); platforms.forEach(function (obj) { obj.body.immovable = true; }); //add Player player = game.add.sprite(32, Ground.y - 60, 'Player'); //physics for the player on!! game.physics.arcade.enable(player); player.body.collideWorldBounds = true; player.health = life; player.body.bounce.y = 0.3; player.body.gravity.y = 400; player.scale.set(2); player.animations.add('move', null, 10, true); player.animations.play('move'); player.events.onKilled.add(resetPlayer, player); //cammera follow game.camera.follow(player); Link to comment Share on other sites More sharing options...
hollowdoor Posted February 15, 2015 Share Posted February 15, 2015 Try doing this:game.world.setBounds(0, game.world.height-200, 1600, 480); or this:game.world.setBounds(0, game.world.height+200, 1600, 480); Link to comment Share on other sites More sharing options...
Foxhunt Posted February 15, 2015 Author Share Posted February 15, 2015 Hi hollowdoor, didn't work. As far as i can tell with using the game.world.height value i just take the existing 280 and and add/subtract 200 and use that value to set the world bounds.The world bounds default to 0, 0, game.world.width, game.world.height, so the upper left corner (0, 0) is the game world's center. And i want to expand the top of the world by value x (i.e.: 200 for testing), so i go extend the game.world.bounds by 200 pixel along the y-axis. Link to comment Share on other sites More sharing options...
hollowdoor Posted February 15, 2015 Share Posted February 15, 2015 Ya. I'm just saying don't put a negative value in the arguments for set bounds. If you want to resize the world just try:game.world.resize(game.world.width, game.world.height + 200);If you actually want to move the canvas up get the id from the canvas, and adjust it's style.top value. I don't know if you mean up physically, or just up in number. btw. You can't have a negative x, or y origin for a canvas so you better use style.top instead. That is unless you're trying to mirror the canvas, but I don't think Phaser is going to like that. Link to comment Share on other sites More sharing options...
Recommended Posts