Hello Guest

Author Topic: How do I get a reference to my tile map?  (Read 3748 times)

kgilbert2

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 13
    • View Profile
How do I get a reference to my tile map?
« on: February 05, 2015, 04:51:07 am »
Hi everyone.

I am new to 2D Toolkit.  My goal is to make a top down 2D game.   To start learning it, I have made a simple script, attached to my camera, to show me the tk2dCamera position using GUILabel, and to get the position for a user's touch on iOS.  I am running into trouble when getting a reference to my "Tilemap" object, cast as a tk2dTileMap. I  attempted to cast by finding it on GameObject, but it is an invalid cast. 

My questions:

What is the correct way to get a tk2dTilemap reference for the Tilemap game object from code?
Would TileMap.GetTileAt() be the correct way to get 0,0 positioned tile if I click in the bottom left corner?

I appreciate any help you are able to offer.

r0l3k

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: How do I get a reference to my tile map?
« Reply #1 on: February 05, 2015, 04:43:18 pm »
If you need a TileMap, in your game object create a field:

public tk2dTileMap myTilemap;

and assign the tilemap in the unity editor.

This will give you the tilemap. Then use the methods of the object to get tiles.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How do I get a reference to my tile map?
« Reply #2 on: February 05, 2015, 09:19:40 pm »
You can't cast a game object, you'll need go GetComponent<tk2dTilemap>();

kgilbert2

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: How do I get a reference to my tile map?
« Reply #3 on: February 06, 2015, 04:43:42 am »
I am able to access it through code now and I am continuing to learn.

Thank you both very much.

:)