1

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

  • There are several clever ways of solving this problem. 441 buttons are not two many. It might not be a good idea for other reasons. Could you show us this map? – candied_orange Aug 22 '16 at 3:08
  • Sure look at the question @CandiedOrange – M4HdYaR Aug 22 '16 at 5:49
1

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.

  • And How can I capture where clicked by the usere? – M4HdYaR Aug 22 '16 at 8:37
  • Depends on what your developing in. Search for "mouse click" and "mouse down". along with your development environment. – candied_orange Aug 22 '16 at 11:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.