1
\$\begingroup\$

I am learning how to code by programming easy, 2D games. Here I want to try to get only a map, like in strategy games (2D isometric) and put new objects (pictures) on it.

In short: I want load a big picture and put little pictures on this big picture.

My thought was:

  1. Find a big map picture. (or make it with Photoshop)
  2. Put a grid-layout over that base (this will not be visible to the player).
  3. Put smaller objects (as pictures) on this map using this grid-layout.

Is it possible to make it like this, or are there better solutions?

\$\endgroup\$
4
  • 2
    \$\begingroup\$ Yes, it's called Tile-based games. \$\endgroup\$
    – Vaillancourt
    Commented Nov 11, 2015 at 21:42
  • 2
    \$\begingroup\$ Is it possible? Anything is. Is it a good solution? That depends on what your goal is. \$\endgroup\$
    – Philipp
    Commented Nov 11, 2015 at 21:43
  • \$\begingroup\$ Yes. Just use an array as your grid layout. \$\endgroup\$ Commented Nov 11, 2015 at 22:16
  • \$\begingroup\$ I'm voting to close this question as off-topic because it shows zero research effort. \$\endgroup\$
    – Engineer
    Commented Nov 12, 2015 at 20:26

2 Answers 2

1
\$\begingroup\$

The easiest way of creating a grid is a 2 dimensional array. You didn't tell what language/game engine you plan to use but a search on arrays combined with your language of choice should give you the information you need. Treat all code examples in this answer as pseudo code- you will have to convert it, but it should illustrate the concept.

An array is basically a list of items that can be accessed by the position in the list. A 2 dimensional array works like a grid. In most languages a 2 dimensional array is represented like this:

Array[x][y]

Now you can put items in the Array at the x and y coordinate, for example place an item at coordinate 3,6 would be:

Array[3][6] = myItem;

If you want to draw a grid, it would be as easy as (suppose the grid is 20x20):

SquareSize = 10
GridSize = 20
for(x=0 to GridSize)
  for(y=0 to GridSize)
    if(Array[x][y].containsitem)
        draw_X_Y_Item(x*SquareSize,y*SquareSize,Array[x][y])
    end if
  next
next

Now you wanted an isometric grid. The trick is that each odd row X is offset 0.5 * SquareSize and the height of each row is 0.5*SquareSize.

SquareSize = 10
GridSize = 20
for(x=0 to GridSize)
  for(y=0 to GridSize)

    if(Array[x][y].containsitem)

      if(y%2=0) // odd or even?          
        draw_X_Y_Item(x*SquareSize,y*SquareSize*0.5,Array[x][y])
      else
        draw_X_Y_Item(x*SquareSize+0.5*SquareSize,y*SquareSize*0.5,Array[x][y])
      end if

    end if 
  next
next

If you also use this method to draw your map; you will save a lot on memory; do a search on 'tilemaps' for more information.

\$\endgroup\$
0
\$\begingroup\$

Yes. But it depends on your goal, whether it's the best solution or not. I would do it like that:

-Create a large array for tiles (grid layout)
-Put on each array the specific texture (grass, sand etc..)
-And put items on the specific tiles.

Huge textures can cause problems on some of the devices like old android phones. E.g they don't support textures larger than 1024px..

So I would use arrays and put each world tile on it.

(Sorry for bad english)

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .