Sign in to follow this  
Batzi

Scaling a map without affecting the placement of a sprite

Recommended Posts

So I am having a problem whenever I am zooming out the map. The scale of all the assets are done correctly except when I zoom out, their position on the map change. I am not changing sprite.x/y, it is just that when the map is scaling things move around and I tried doing something like

//pseudo-codeif(zoomOut){  sprite.x *= scale;  sprite.y *= scale;}

but that didn't work since that sent the sprites off the map eventually.

 

Here's an example of what is going on.

 

So this is the game when zoom is maxed out (scale=1)

 

image.png

 

this is when the scale is 0.9 (you can see the sprites aren't where they were originally placed)

 

image.png

 

At scale=0.7 (now it is even more obvious)

 

image.png

 

What do you guys think?

Share this post


Link to post
Share on other sites

 

I added the sprites to a screen group and scaled accordingly :

 

game.input.onDown.add(function() {    scale -= 0.1    screenGroup.scale.setTo(scale, scale);}, this);
 
 
Hope this helps

 

Thank you! That's perfect! I was scaling the sprites individually. Adding them to a group is smarter and easier to handle! :)

Share this post


Link to post
Share on other sites

I had assumed you might not want to scale the sprites, but you appear to have fixed what you need

 

I had made this anyway as a rough test in that case

http://phaser.io/sandbox/GKTRPIOi/play

 

W,A,S,D and NumPad +/- to scale

 

I should probably have used the camera though instead of shifting the map

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.