Adam's Lair Forum

game development and casual madness
It is currently 2017/12/16, 09:01

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 11 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: TileMap Basic Infos
PostPosted: 2017/06/14, 10:28 
Novice Member
Novice Member

Joined: 2017/04/23, 09:34
Posts: 18
Location: Germany
Role: Hobbyist
Hi fellow Coders,

i am currently quite interested in the TileMap system and sadly missed the TileMap Jam T.T
I allready researched for posts or examples to check for the tilemap handling in duality but still i quite don't get how to use it propperly codewise.

Is there a extendet tutorial which shows how to set up and use tilemaps on codeside and how to build for example a mechanic to generate specific tile patterns to create levels with it by code?

I was thinking of creating a levelgenerator which uses for example external data(in text or tables) to create predefined but changeable TileMaps and move a camera/player over that map. For performance reasons i would like to render the needed tiles on sight. Is there a way to do this in advance? Or is there maybe an easier way to create such a system by using the TileMap extension propperly ? xD

Greetings
4lexKidd


Top
 Profile  
 
 Post subject: Re: TileMap Basic Infos
PostPosted: 2017/06/14, 15:24 
Veteran Member
Veteran Member
User avatar

Joined: 2015/10/04, 15:48
Posts: 162
Location: Germany
Role: Hobbyist
Hello 4lexKidd ^^

4lexKidd wrote:
Is there a extendet tutorial which shows how to set up and use tilemaps on codeside and how to build for example a mechanic to generate specific tile patterns to create levels with it by code?


As far as I know, there isn't any tutorial besides the Tutorial by Adam.

The first step is to reference the Tilemap-Plugin (Tilemap.core.dll) to your VS Project.
After that you can great your custom component (e.g MapController), which can generate Layers.

Here is an extract from my school project (Bomberman-Clone):
Code:
private GameObject CreateLayer(GameObject map, int layerId, int width, int height)
{
   var layer = new GameObject("Layer" + layerId, map);
   layer.AddComponent<Transform>();
   layer.AddComponent<TilemapRenderer>();

   var tileMap = layer.AddComponent<Tilemap>();
   tileMap.Tileset = mapTileset;
   tileMap.Resize(width, height);
   tileMap.Clear();

   // fill the map
   for (int y = 0; y < height; y++)
   {
      for (int x = 0; x < width; x++)
      {
         // layer 1
         if (layerId == 0)
         {
            // MapBorder
            if (x == 0 || y == 0 || x == width - 1 || y == height - 1)
            {
               tileMap.SetTile(x, y, new Tile(WALL_ID));
            }
            else
            {
               if (x % 2 != 0 || y % 2 != 0)
                  tileMap.SetTile(x, y, new Tile(FLOOR_ID)); // Floor
               else
                  tileMap.SetTile(x, y, new Tile(WALL_ID)); // Walls
            }
         }
         else
         {
            tileMap.SetTile(x, y, new Tile(AIR_ID));
         }
      }
   }
   
   // [...]

   return layer;
}


You could also dig in the source code to find what you need:
Click me

Greetings
Cross

_________________
Twitter | GitHub | Join Duality on Discord | itch.io


Top
 Profile  
 
 Post subject: Re: TileMap Basic Infos
PostPosted: 2017/06/15, 10:36 
Novice Member
Novice Member

Joined: 2017/04/23, 09:34
Posts: 18
Location: Germany
Role: Hobbyist
Hey Cross,

awesome thanks for the advice and the code snipped.
That helped alot ;)

Just some little questions about that snipped to fully understand it:

-mapTileset, width and hight are properties of the map that was created/assigned in the editor, right? And therefore can be checked or manipulated?
-what is the AIR-ID for ? As far as i understood the code it generates a outer wall + a wall tile every 2. tile and fill the rest with floor-tiles. Is that right?


Top
 Profile  
 
 Post subject: Re: TileMap Basic Infos
PostPosted: 2017/06/15, 12:48 
Veteran Member
Veteran Member
User avatar

Joined: 2015/10/04, 15:48
Posts: 162
Location: Germany
Role: Hobbyist
4lexKidd wrote:
mapTileset, width and hight are properties of the map that was created/assigned in the editor, right? And therefore can be checked or manipulated?

Yes, thats right. You can creat public properties to modify them in the editor... just an usability thing..
Code:
public ContentRef<Tileset> MapTileset
{
   get { return mapTileset; }
   set { mapTileset = value; }
}

4lexKidd wrote:
what is the AIR-ID for ? As far as i understood the code it generates a outer wall + a wall tile every 2. tile and fill the rest with floor-tiles. Is that right?

That's also right.
Code:
public const int AIR_ID = 0;
public const int WALL_ID = 2;
public const int FLOOR_ID = 3;

The AIR_ID ist just the empty tile in the tileset.

This is an example how it looks like:
Image

_________________
Twitter | GitHub | Join Duality on Discord | itch.io


Top
 Profile  
 
 Post subject: Re: TileMap Basic Infos
PostPosted: 2017/06/19, 06:59 
Novice Member
Novice Member

Joined: 2017/04/23, 09:34
Posts: 18
Location: Germany
Role: Hobbyist
hmm allright and i guess i understand the mechanic behind the tilesets a little better but i guess i need to dig a little more into some examples ^^

Quote:
This is an example how it looks like:


aahh good old bomberman for the snes xD loved that game back then ^^ would absolutely make a good training project for all sorts of stuff ;) :idea:


Top
 Profile  
 
 Post subject: Re: TileMap Basic Infos
PostPosted: 2017/06/19, 13:59 
Veteran Member
Veteran Member
User avatar

Joined: 2015/10/04, 15:48
Posts: 162
Location: Germany
Role: Hobbyist
if you have any further questions, feel free to ask ^^ :1+:

_________________
Twitter | GitHub | Join Duality on Discord | itch.io


Top
 Profile  
 
 Post subject: Re: TileMap Basic Infos
PostPosted: 2017/06/19, 18:29 
Veteran Member
Veteran Member
User avatar

Joined: 2016/01/10, 10:56
Posts: 148
Location: Budapest
Role: Hobbyist
Hey!
Cross wrote:
4lexKidd wrote:
Is there a extendet tutorial which shows how to set up and use tilemaps on codeside and how to build for example a mechanic to generate specific tile patterns to create levels with it by code?


As far as I know, there isn't any tutorial besides the Tutorial by Adam.

Apparenty, there is a two part series on the topic authored by humble me. Maybe I should have advertised it more :]

http://www.packtpub.com/books/content/create-dynamic-tilemaps-duality-c-%E2%80%93-part-i
http://www.packtpub.com/books/content/create-dynamic-tilemaps-duality-c-%E2%80%93-part-ii


Top
 Profile  
 
 Post subject: Re: TileMap Basic Infos
PostPosted: 2017/06/19, 22:19 
Member
Member

Joined: 2016/08/03, 22:07
Posts: 50
Location: Florida
Role: Hobbyist
Nice tutorials @loeller! We should do another Jam!


Top
 Profile  
 
 Post subject: Re: TileMap Basic Infos
PostPosted: 2017/06/20, 07:10 
Novice Member
Novice Member

Joined: 2017/04/23, 09:34
Posts: 18
Location: Germany
Role: Hobbyist
@loeller Nice tutorials and i will dig into them a little further soon but just a question ahead:

What do these lines mean? :
Code:
private Tilemap         TilemapInScene         => this.GameObj.ParentScene.FindComponent<Tilemap> ();
private TilemapRenderer TilemapRendererInScene => this.GameObj.ParentScene.FindComponent<TilemapRenderer>();
private Camera          MainCamera             => this.GameObj.ParentScene.FindComponent<Camera> ();


Is this just oldschoolish pointer handling or what does this arrow mean/achieve in the code?(sorry for a possible noob-i question; i haven't that much of experience in c# to base on ^^)


Top
 Profile  
 
 Post subject: Re: TileMap Basic Infos
PostPosted: 2017/06/20, 11:06 
Veteran Member
Veteran Member
User avatar

Joined: 2016/01/10, 10:56
Posts: 148
Location: Budapest
Role: Hobbyist
Thank you 4lexKidd and RollerJesus!
Nope, you usually don't need to deal with pointers explicitly in C#. No wonder that you are unfamiliar with these statements, they were introduced recently, in C#6. They are shorthands for read-only or getter properties. I used them just to be shorthands for the lengthy expressions of finding specific components in the scene.

Basically this:
Code:
private Tilemap         TilemapInScene         => this.GameObj.ParentScene.FindComponent<Tilemap> ();

is the same as this:
Code:
private Tilemap TilemapInScene {
  get {
    return this.GameObj.ParentScene.FindComponent<Tilemap> ();
  }
}

Is it clear for you? Feel free to ask if you have additional questions :]


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group