# [XNA] 2D Tile Map, Best way to 'Zoom'?

## Recommended Posts

Hi guys, I have a 2D map editor in front of me. the idea is that it is used to create a maze by drawing textures .... these map can be as big as 100x100 and everyone who has tested it for me has said "I want the Ability to Zoom Out so I can see my entire map". Now i thought this would be a simple idea, simply change the size of the tiles when they draw by using a TrackBar on windows forms to control the value. However I don't really get the effect I was looking for .. just smaller tiles. Is there a more effective way for scaling to zoom, or is this the best way?

##### Share on other sites
I'm assuming you are using SpriteBatch to render your tiles? If so pass a scale matrix into the worldMatrix parameter.

Scott

##### Share on other sites
Yes, I am calling Spritebatch.Draw() to draw these (:P forgot to mention)

I never knew that I could use a matrix however. I can only use a positive float for this.

Matrix.CreateScale(ztrackBar.Value);

Because I draw my tiles with a size of Tx,Ty how could I create a negative scale change the way it or will I have to change the way it draws?

this seems to do [TileSize * scal]e, where as I was doing [TileSize / value] so i simaplly get a reverse effect.

##### Share on other sites
I'm confused as to what exactly you're trying to accomplish. If you want to zoom out to see the entire map, 'smaller tiles', as you say, are exactly what you want.

Using a scale matrix does indeed do a [TileSize * scale] essentially. You just want your 'scale' to be between 0 and 1. If you want to 'zoom out', you want values less than 1 (but not negative).

##### Share on other sites
Scale, by default, is 1.0

Think of this as 100%

If you want 50%, then you use 0.5

If you want to zoom in to 200%, then you use 2.0

##### Share on other sites
yea, the one problem I have come across is the Track Bar will only take int values so I cant have < 0.5 as it rounds to 0;

##### Share on other sites
Quote:
 Original post by Andy474yea, the one problem I have come across is the Track Bar will only take int values so I cant have < 0.5 as it rounds to 0;

Sure you can :)

Just divide the track bar's output by 10 (or some other numbe that gets you the result that you're after).

Track Bar output = 5

5/10 = 0.5

##### Share on other sites
yes 5/10 = 0.5 but when passing that as an int

int a = 5/10 :: outcome = 0

1/10 = 0;
2/10 = 0;
3/10 = 0;
4/10 = 0;
...
9/10 = 0;
10/10 = 1;

this is how my game gets the withEngine.Tile2DWidth = 52;public int EngineTileWidth{     get {return Engine.Tile2DWidth / (zTrackBar.Value / 10)};}

so this imo ALWAYS return 0; unless i have 10/10 then i get 1.

##### Share on other sites
Make the track bar value a float or cast to float when you use it ...

##### Share on other sites
You need to have at least one float in the division, or to be casting something as a float...

5/1.0f = 0.5f

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627642
• Total Posts
2978354

• 10
• 12
• 22
• 13
• 33