Question

I'm creating A Map like Travian on Xamarin forms

My map is something like 5000*5000

The way I want to do that is to load part of the map (21*21) of the big map where the current village is the center of the 21*21 map but show a 7*7 map to user(Again current village center of it)

So when user scrolls the map, can see the other parts of loaded map(21*21) and when the user reached end of the scroll, The map reloads...

But my question is when I want to do that I need to have something like 440 Buttons(Each button each tile of the map) ... Is it uses too much memory ?

Edit : The example of the map

Was it helpful?

Solution

That's an isometric map. There are many ways to handle it. But if you feel like using math to solve the problem here are a few projection formulas.

Given mouse clicks on the screen you can find the maps cords with:

map.x = (screen.x / TILE_WIDTH_HALF + screen.y / TILE_HEIGHT_HALF) /2;
map.y = (screen.y / TILE_HEIGHT_HALF -(screen.x / TILE_WIDTH_HALF)) /2;

Given map cords you can project to the screen with:

screen.x = (map.x - map.y) * TILE_WIDTH_HALF;
screen.y = (map.x + map.y) * TILE_HEIGHT_HALF;

How this math is derived can be seen here.

Since the map can be scrolled you will need to add the scroll x and y to these calculations.

Here's a fairly good introduction to isometric graphics.

Licensed under: CC-BY-SA with attribution
scroll top