Jump to content

Anchor for oversize sprite?


kawanua
 Share

Recommended Posts

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

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

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...