Jump to content

How to reposition sprites after a game setGameSize


kiwi
 Share

Recommended Posts

Hi,

 

when creating the game using the Game constructor I'm defining the width and height of canvas. Later, using the Phaser.Device detection I'd like to change the game size. I'm using the 

game.scale.setGameSize(1920,1080)

but the images and sprite are not centered.

I'm trying a way to reposition all elements correctly in this new dimensions but I can't find the scaleManager method to achieve this. Could you help me pls?

 

thanks

Link to comment
Share on other sites

Hello

I'm not sure about scaleManager methods...
But you can use one big sprite as container. Just add all game imges and sprites via "addChild" and than set container position to center.
Don't forget, after addChild we should use checkTranform method and update sprite bounds by this way - http://www.html5gamedevs.com/topic/18495-how-to-update-bounds-for-nested-sprites/
Link to comment
Share on other sites

 

Hello

I'm not sure about scaleManager methods...
But you can use one big sprite as container. Just add all game imges and sprites via "addChild" and than set container position to center.
Don't forget, after addChild we should use checkTranform method and update sprite bounds by this way - http://www.html5gamedevs.com/topic/18495-how-to-update-bounds-for-nested-sprites/

 

 

 

thanks for your reply but I think I was doing something wrong. I was setting the new size immediately after the new Game function. Instead I moved that to the first stage Create call and everything is aligned perfectly 

Link to comment
Share on other sites

Here's how I do it

//Assume original scale is 1 (100%)sprite1;sprite2;allSprites = game.add.group();allSprites.add(sprite1);allSprites.add(sprite2);//let's get a random scale between 0 and 1 (0%-100%)scale = 0+Math.random()*1;//now let's scale the group and have them maintain their positions with respect to the new scaleallSprites.scale.set(scale);

You also have to adjust camera bounds if you're scrolling around on the map.

 

Not sure if this answers your question.

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...