Hello Guest

Author Topic: Unloading a TileMap / switching data and rendering.  (Read 5315 times)

Square

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 25
    • View Profile
Unloading a TileMap / switching data and rendering.
« on: February 11, 2013, 12:38:05 am »
A bit of a problem with switching TileMap "data", as I'd like to eventually "change levels" during runtime in a Unity scene.

I'm not sure looking at the selectors on the Unity GUI which type of object/asset contains the essential "tilemap data" and what exactly draws the render data.

There is under Settings tab for my Tile Map main Object:

Tile Map Data
Editor Data
Sprite Collection (don't worry I understand this!)
Render Data (which I can see is a target gameObject in the Scene Hierachy)
Make Unique
Make Serializable

I hope you understand, I'm a little confused by the purpose of all these.

I guess I'm asking, under currently functionality what is the most efficient way within a Tk2dTileMap object to...

1) Unload a TileMap
2) Destroy the render data
3) Switch data
4) Telling 2dtk to render out the level

Seems the right approach for me, I hope you can shed some light on the subject ;)

Thanks.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Unloading a TileMap / switching data and rendering.
« Reply #1 on: February 11, 2013, 10:23:56 am »
Tilemap data stores all the tilemap set-up properties, like the layers, prefab set up and so on. It contains all the data required to generate the tilemap at runtime.

The tile data is stored on the tilemap object in your scene.

Editor data stores the saved brushes, etc for use in the tilemap editor.

The render data contains the gameobject, and this in turn contains all the render meshes which are used to draw the tilemap on screen.



Destroy a tilemap by destroying both the tilemap object & the render data object.

How are you going to switch data? If you're saving each level as a scene, you could just load the new scene in, and then you wont have to care about destroying the tilemap, creating a new one, etc. That is the simplest and most Unity friendly way to do this.

Square

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Unloading a TileMap / switching data and rendering.
« Reply #2 on: February 11, 2013, 01:04:57 pm »
Perhaps Unity friendly as I'm destroying game objects... but I'm not saving each level as a scene.

If you can imagine, my game has sub-levels which can be anything from a scrolling level of width 128 tiles, to a fixed level of 20 odd tiles (for a room or small level).

Essentially, my game is not linear left to right, but levels with exits left, right, up and down. This requires a grid of data I want to call from. Also I'm automating a function where one level leads to another. I don't want them as seperate scenes because I'd have hundreds eventually.

Also... thinking in terms of what stays constant throughout a game visually, scoreboard, other onscreen items. That's not mentioning all the constant things in a game that will effectively cut-off and reinitialised when changing scene.

I don't think I'm wrong about this ;) at least in my approach:
  • Play is paused, game camera graphics will fade out
  • The rendered level will be destroyed
  • Tile Map data is changed
  • The scene renders the tiles
  • Fade in the game window, play resumes

Otherwise I'm practically unloading the game engine I have built and loading everything all over again.

I hope you understand the need for changing level data within one scene, thus "on-the-fly". Therefore you would need functions to build a level. If I cannot do this, I'd have a lot less options.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Unloading a TileMap / switching data and rendering.
« Reply #3 on: February 11, 2013, 01:34:01 pm »
You can still do this with each tilemap level in its own unique scene. It still plays to Unitys strengths doing it this way.

1. What you do is you have your scoreboard, and other initialization stuff in one scene.
Your main scene doesn't have any tilemap data, but just knows what "level" to load.

2. Each level / sublevel / whatever in its own scene, without any of the auxilary stuff. We'll call it "tilemap scene"

So when you load your game, you start with the main scene, and then LoadLevelAdditive the relevant tilemap scene. If you want to load a second scene, delete the tilemap & tilemap render data object, load the next scene using LoadLevelAdditive. Thats it really - you treat each "scene" as the tilemap data.

Now you can go further than that, using LoadLevelAdditiveAsync, you can load your scenes in the background without fading out and or pausing. You can effectively stream the entire game world that way. If you plan it properly, you can set it up that the correct "sector" is loaded when you are approaching it.

Doing any asynchronous stuff without scenes is quite a bit more tricky, especially when you need to regenerate all the mesh data - it'll be a LOT quicker loading a scene additively.

Square

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Unloading a TileMap / switching data and rendering.
« Reply #4 on: February 11, 2013, 02:25:47 pm »
Thanks very much.

I was unaware you could add Scenes in. Thanks for pointing that out. I was thinking Scenes could only be "switched"

With this in mind you are totally correct, brings to mind I have plenty of options ;) using a Game scene, and Level scenes.

It's not your job to tutor Unity solutions.... so thanks for your advice and bearing with me.