Jump to content

Scaling a map without affecting the placement of a sprite


Batzi
 Share

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?

Link to comment
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! :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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