Sign in to follow this  
Andy474

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

Recommended Posts

Andy474    694
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 this post


Link to post
Share on other sites
Andy474    694
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 this post


Link to post
Share on other sites
Nairb    766
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 this post


Link to post
Share on other sites
NightCabbage    100
Quote:
Original post by Andy474
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;

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 this post


Link to post
Share on other sites
Andy474    694
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 with

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