Hello Guest

Author Topic: Generating a map  (Read 7410 times)

K.V.

  • Newbie
  • *
  • Posts: 4
    • View Profile
Generating a map
« on: July 02, 2012, 10:04:56 am »
Hi. I have a question about generating a map in runtime. Map, which I need to create, is exactly an island and sea around it. The problem is that the distance between island and sea is not fixed and can be changed before creating, as well as size of whole map. So I can't just create a texture and attach it to sprite. I solved this problem by creating a lot of sprites, using prefabs, each one for different type of landscape, and adding sprites to one game object which can be scaled. But I'm not sure that it won't require too much memory. Maybe you can suggest some better way to do this? For example, render to texture or something like that.
« Last Edit: July 02, 2012, 10:36:03 am by K.V. »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Generating a map
« Reply #1 on: July 02, 2012, 07:12:16 pm »
What kind of map is this? Tilemap? Just positioned sprites?
I'm finding it a bit difficult to picture what you're after exactly - a screenshot could explain a lot.

If you need to move to private discussion, use the private support forum or email support@unikronsoftware.com, if not simply post here. Unless you have a TON of sprites (and I mean LOADS), memory overhead is going to be fairly low. Render to texture will work, but will require a full rendertarget the size of the full texture, but unsure is it really necessary. Again a pic would explain a lot more than words would - I will hopefully be able to make some more specific suggestions then :)

K.V.

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Generating a map
« Reply #2 on: July 04, 2012, 09:15:15 pm »
Thanks. :) Here's a picture. Map looks like this. Red and pink lines show sizes, which can be changed before start, through variables. Also, vertical and horisontal sizes are not neccesary the same. They can be different, and so, map can be rectangle, not exactly square. Logically, it's a tilemap, but we use just a lot of positioned sprites. And not sure that it's a good method :)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Generating a map
« Reply #3 on: July 04, 2012, 09:19:01 pm »
Thanks. :) Here's a picture. Map looks like this. Red and pink lines show sizes, which can be changed before start, through variables. Also, vertical and horisontal sizes are not neccesary the same. They can be different, and so, map can be rectangle, not exactly square. Logically, it's a tilemap, but we use just a lot of positioned sprites. And not sure that it's a good method :)

Just use the tilemap feature. You can change tiles at runtime.
Create it with the correct world size (256x256 will do, it doesn't allocate full memory until needed), and set up the sprite collections, etc. After that, at runtime -
tileMap.Layers[0].SetTile(x, y, tileId);
and after you're done,
tileMap.Build();

That's basically it :)

K.V.

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Generating a map
« Reply #4 on: July 04, 2012, 09:34:06 pm »
There's another question then. :) I tried to create tilemap before, using this tutorial
http://unikronsoftware.com/2dtoolkit/doc/tilemap/Tutorial.html
But when I click Edit, there are no atlas in the bottom right corner. Just the line
"Sprite collection       data". I dragged another data there but nothing had changed. And also full interface didn't appear. What's wrong?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Generating a map
« Reply #5 on: July 04, 2012, 10:09:02 pm »
Have you definitely created the "Tile map Data" and "Editor Data" objects? The editor won't be available until they are valid.

K.V.

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Generating a map
« Reply #6 on: July 07, 2012, 05:34:15 am »
Thanks, now everything is fine. :) Except one thing. When I click on tilemap and try to make picking object, function PickObject returns null. Looks like tilemap is not a collider. Though colliders of the sprite collection, which is used for tilemap, are set to Box trimmed. :)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Generating a map
« Reply #7 on: July 07, 2012, 12:30:29 pm »
Ahaa. This isn't obvious, but when you set the collider to box trimmed, the front and back faces of the box are omitted. It is fine in most cases, but picking breaks. You can sort this out by switching the collider type to Polygon, and then set the cap to front or front & back.