kawanua Posted October 26, 2015 Share Posted October 26, 2015 Hi, Im having trouble to set the start location for an oversized background sprite. Using this example (http://phaser.io/examples/v2/camera/world-sprite), when the page is loaded, the canvas shows only the top left of the background sprite. Is there anyway to make the canvas to show certain coordinate or even the middle of the background sprite when the page is loaded ? Thanks ! Link to comment Share on other sites More sharing options...
drhayes Posted October 26, 2015 Share Posted October 26, 2015 You *probably* want to set the camera x/y... which means you'd have to move your player sprite and any enemies as well. Check out "this.game.camera.x" and "this.game.camera.y". Link to comment Share on other sites More sharing options...
kawanua Posted October 27, 2015 Author Share Posted October 27, 2015 Hi drhayes, Thanks for the suggestion. It still doesnt work.thebg = game.add.sprite(0, 0, 'background');game.world.resize(1920, 1200);this.game.camera.x = game.world.centerX/2;this.game.camera.y = game.world.centerY/2;theSprite = game.add.sprite(game.camera.x, game.camera.y, 'thesprite');Its still appear not exactly in the middle of the screen. On separate issue, in the same example, how to lock the sprite in te middle of the screen when scrolling through a big background ? In any example in Phaser.IO, the character still can move around although the scroll already ends Link to comment Share on other sites More sharing options...
drhayes Posted October 28, 2015 Share Posted October 28, 2015 What doesn't appear exactly in the middle of the screen? Do you mean that your sprite is offset a little bit to the right and down? You added your sprite to the camera.x/y; did you want it at the center of the world, instead? You can set "fixedToCamera" on the sprite to true like this: "sprite.fixedToCamera = true;". You can then set the sprite "cameraOffset" property to center it in the screen. EDIT: Can you post this on the sandbox or on a jsfiddle or something? That way I can see what you mean. Link to comment Share on other sites More sharing options...
Recommended Posts