Jump to content

  • Log In with Google      Sign In   
  • Create Account

WunderStrudel

Member Since 16 Jun 2013
Offline Last Active Jun 29 2014 10:04 PM

#5163163 Unity 2D tiled maps

Posted by WunderStrudel on 26 June 2014 - 11:28 PM

Making a tile engine in 2D is very easy, especially  using unity. (: 
Basicly you only need 3 main functions. 

generateTileMap() {

    This Function is gonna "generate" the values, to fill into a 2D array (public int[][] foo = .....). so basicly the information you need for the different block types.

 

}

 

buildTileMap () {

    in here you are gonna go through your 2d array "foo" and place a different texture, decided by the value at it's cords in the 2d array. 

 

}

 

generateCollision() {

    This is basicly where you make the collisions, also decided by the value value at it's cords in the 2d array. for example. 

    

    for (int x = 0; x < blocksX.length(); x++) {

         for ( int y = 0; y < blocksY.length(); y++) {

               

               if (Block[x][y] == 1 ) { // Dirst Maybe

                   Collider();

               } else if (Block[x][y] == 2) { // Water maybe

                  then execute whatever you want to happen when in the water. 

 

               }

         }

    }

   

}

 

And just so it is said!! d: 
The code above is NOT! working code. it is only for example purpose, i'm not really sure if it is half java and half c++, havent really written in c in a while. So dont copy paste any of the code, it surely wont work. (: 

Hope you make it work, if not i think i have an old project laying around, where i build a 2D tile engine you could take a look at. you can just pm me. 
Sincerly WunderStrudel.




PARTNERS