Hello Guest

Author Topic: Tilemap for a Runner Game  (Read 6414 times)

grcwar

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 4
    • View Profile
Tilemap for a Runner Game
« on: August 22, 2013, 03:32:53 pm »
Hello! I'm a game developer from Brazil, used to work with Unity on 3D and now really beginning the 2D world to build a "runner" game, just like Subway surfers but on 2d.

I'm studying the 2D toolkit and so far it has been great, also I have read many questions about tile maps on the forums, but I would like to ask you help to clarify the following points:

1) Using the toolkit what would be the best architecture to build the tile sequence for a level? I mean, we have many sequences of tiles, with different sizes, and we would like to load them randomly to build the path in which the player will pass by. So we don't know if we should use like a tilemap (really helps a lot building the sequence) or if we should have just gameobjects containing the sequences of individual sprites and the go instancing them according to the player progress.

2) In our current structure we have some layers that move together to build a parallax effect: One for the background sprites, other for some game scene elements, and a third one for the elements that really are going to interact with the player, like obstacles and power-ups. We are keeping the camera and the player stoped, so all the other layers are moving... are we on the right track? 

3) Also, as far as I could find on the forums, seems like it's not a good idea moving the tileMap object right? So, if we decide to use the tilemaps to build the sequences of obstacles, how can me move then? We will need to load and unload some data since the game has no end.. does it work with many tilemaps on the same scene?

4) If the tilemap is not the right solution to do this... Then going into the gameobject sequence idea..  If we have , 100 or 500 sprites in each gameobject that contains a sequence, an load and unload it every second for intance, may it perform well?

Thanks for making this great product... really enjoying to work with it!
« Last Edit: August 22, 2013, 10:20:46 pm by grcwar »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: TileMap for a Running Game
« Reply #1 on: August 22, 2013, 10:36:02 pm »
Hi!,

1. One easy way to do this is using the static sprite batcher. Simply create a static sprite batcher for all your different sections, and then instantiate them as needed. Or better yet, simply have it hidden in the scene and just move it to position.

2. Probably not the best thing to be doing here. You should probably do a combination of things. You don't want to move the colliders all the time as it will be a LOT more efficient to move the player than them every frame. You also don't want to move to far away from the origin, so you should do a combination.

A B C

A B C D (as player moves on)

   B C D (unload A)

B C D (move back to origin, and move your player together).

3. With the static sprite batcher, you merge all your sprites down to one object - it is considerably quicker to spawn than the same number of sprites.


The tilemap could work too, but it isn't optimized for quick spawning, or moving. It will work, but the solution above is likely to be more efficient.

grcwar

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Tilemap for a Runner Game
« Reply #2 on: August 23, 2013, 01:13:00 pm »
Hello Unikron!

Thank you for clarifying all those points, and for pointing out the static sprite batcher.

I will miss using the tilemap editor with is simply awesome! But i think we can manage that..  =)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Tilemap for a Runner Game
« Reply #3 on: August 23, 2013, 01:58:36 pm »
If you would really like to use the tilemap editor, you could write an extension to it to create a batcher.
Iterate through x and y for tile map, and foreach tile that isn't -1, create an entry for the batcher, use tilemap.GetTilePosition to work out the position the tile should be at.

It should be fairly straightforward.

grcwar

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Tilemap for a Runner Game
« Reply #4 on: August 28, 2013, 02:19:41 pm »
Hello Unikron.. been working on the last days and managed to get things working fast with your tips, but now I'm running in another issue, my objects are stuttering while I move them, or even if I let them stopped and move the camera. Almost every second!

Clearly it's not related with the 2D Toolkit, but a Unity problem since you can get the same problem with a simple scene containing a camera and some cubes, and start moving the camera at a fixed rate on the Update/FixedUpdate.

I've  searched about it, found many complains about that and tried most of the solutions discussed in the forums: FixedUpdate, smoothing the Time.deltaTime, Disable VSync, disable dynamic batching.. etc..  nothing worked =( .

In this post http://forum.unity3d.com/threads/135991-Camera-Stutter, you said that Unity guys fixed this kind of issue.. did you have any thoughts to workaround this problem or maybe some news on this?

Just as additional info, running the profiler on the editor I get some spikes on the Render.SetActive() method that matches the timing of the stutter that I see (picture attached). On Android and W8 devices I get the same problem, but there's nothing outstanding on the profiler. Also attached a very basic project that shows the problem.












unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Tilemap for a Runner Game
« Reply #5 on: August 28, 2013, 05:31:27 pm »
I don't really know much more about the stuttering, sorry. Having said that though, I've never really noticed it lately - eg. the tilemap demo has a follow cam there, which doesnt look like its stuttering to me, even when running on a Nexus7 or the few other android devices we tested on. Maybe I've just got used to it?

I'm not sure about Render.SetActive either - I've got a feeling the profiler is lying...

grcwar

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Tilemap for a Runner Game
« Reply #6 on: August 28, 2013, 05:49:41 pm »
Yeah, this stuttering thing is kinda frustrating  :-[

Anyway I found many post and examples of the problem, things from 2010 to nowadays just like this great sample http://marrt.elementfx.com/SmoothMovementTest.html

Lot of people trying interpolation, extrapolation but none got a final solution. Seems to be dependent of hardware, Unity and other things too.

I really don't care about the editor, the problem is seeing this thing on the device too.

Thanks anyway!