Hello Guest

Author Topic: tk2dCamera with my Tile map.  (Read 10463 times)

storm33229

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 23
    • View Profile
tk2dCamera with my Tile map.
« on: March 11, 2012, 06:41:31 pm »
I have attached two images that depict the problem I am having. What I would like to do is:

Set my camera to (0, 0, -10) and have it draw from the top-left down and to the right, such that it draws x pixels to the right and y pixels to the down directions. Right now, if  I set both my objects and camera to (0, 0) nothing gets seen on the game window.

Let me know if you  need more info.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dCamera with my Tile map.
« Reply #1 on: March 11, 2012, 07:50:12 pm »
Theres currently a bug with tk2dCamera and the camera preview :( It uses a custom projection matrix, and the camera preview (and the camera bounds in the viewport) doesn't actually reflect what is seen by the camera. The only way to correctly display the output is to look at the game window.

In your case, my guess is the your tilemap is very very small compared to the the output - what is the spritecollection setting orthoSize & targetHeight? It should appear correctly (at the right scale) if the tk2dCamera setting is ticked.

My best advice to figure out whats going on is to tick the Use tk2dCamera tickbox on the spritecolleciton, and then place one sprite in the scene at 0, 0, 0 and note where it appears in the game window. It should be at the bottom left of the screen. Keep in mind that if you do this and revert, you will have to set up your orthoSize & targetHeight parameters on the sprite collection again.

It does make sense when you understand whats going on, unfortunately with those two bugs there, it makes it really hard - I apologise for the inconvenience, and I am actively working out a nice solution to this.

storm33229

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: tk2dCamera with my Tile map.
« Reply #2 on: March 11, 2012, 09:18:18 pm »
The images I attached are using SpriteCollection's which have 'Use tk2d Camera' set to true.

When I place the sprite at (0, 0) it does not appear, but when I move it up a bit then it starts to show. It looks like the sprites are drawing from the top-left and not the bottom-left?

In fact, that is what was happening. I just changed my Sprite Collection's Sprite Sheet's Anchor to Lower-Left instead of Upper-Left, and now the entire first row of the tile map shows.

I suppose I could rewrite my game logic and map creation code to work with positive-only y positions instead of negative-only y positions. I just would love to have an option for which way the camera behaves.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dCamera with my Tile map.
« Reply #3 on: March 11, 2012, 09:25:12 pm »
If you need it to work the other way for now, you can simply use a normal ortho camera. What I'll be doing in the next release is I'll be adding options in tk2dCamera to support different types of cameras (simple ortho, auto 1:1 correcting ortho, etc) to make this a whole lot easier and straightforward.

If you think the anchors are incorrect in the tk2dCamera (they should not - the coordinate system is x-right, y-up, same as any normal ortho camera) could you please send me a test case project where you can demonstrate this (support at unikronsoftware dot com) and I'll see whats going on.

storm33229

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: tk2dCamera with my Tile map.
« Reply #4 on: March 11, 2012, 09:39:28 pm »
Oh everything seems to be working just fine. The coordinate system is x-right, y-up. I was just wanting to make x-right y-down. The anchors were not wrong on the camera, they were wrong on the sprite sheets inside the sprite collections.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: tk2dCamera with my Tile map.
« Reply #5 on: March 11, 2012, 10:24:43 pm »
Ah ok. That makes a bit more sense.

Making the tk2dCamera y-down would require the models needing flipped on the Y axis - this will be a bit of a pain.

In my tilemap editor, the tiles start at 0,0 at the bottom left, and the "brushes" I use to paint on it start at 0, 0 at top left as it makes a bit more sense to think of it in that way. It sounds a bit counterintuitive, but all it takes to switch from one to the other is a y = height - 1 - y;

How do you generate your tilemaps? I could add some support for importing different external tilemap formats to my tilemap editor if it would be of any use.


storm33229

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: tk2dCamera with my Tile map.
« Reply #6 on: March 11, 2012, 10:40:59 pm »
I use Tiled. I wrote a C# conversion to deserialize the XML into an object model which is in turn used in conjunction with 2D Toolkit to generate the maps at editor-time. I actually don't use Unity for anything other than rendering and game logic; all the world design is done in Tiled.