2D Toolkit Forum

2D Toolkit => Support => Topic started by: iSamurai on April 14, 2014, 03:39:48 pm

Title: Tilemap flickering
Post by: iSamurai on April 14, 2014, 03:39:48 pm
Hi Im using 2d toolkit 2.4 & Unity 4.3.4 to create a tilemap.
I set the tilemap's sprite colletion's pad mode to "Extend".

During game play, there is a line shape flickering from time to time, and only lasts for about 1 frame. And the flickering is quite random, and is difficult to reproduce but when i play the game it just appears suddenly and next frame disappear.
In the game the camera moves quite a lot, not sure whether it is the cause, but it seems the flickering stops when the camera is static.

To confirm it, I draw the tilemap using 1 black sprite. And I test using different camera background color, white, red, orange. And the line shape flickering occurs in white, red, orange correspondingly. So I guess it's the tilemap does not aline correctly under some situation.

Any ideas?
Thanks :)
Title: Re: Tilemap flickering
Post by: unikronsoftware on April 14, 2014, 07:10:31 pm
Keeping the camera snapped to pixels helps - eg. if you're using a tk2dCamera with pixels per meter, make sure the position is a multiple. Eg. if 100 pixels per meter, x = Mathf.Round(x * 100) / 100.
Title: Re: Tilemap flickering
Post by: iSamurai on April 15, 2014, 01:11:57 pm
Thanks it solves the problem :)
but i'm wondering if there is other way to fix the problem? as rounding the camera position makes the camera movement a bit blocky as I was doing pixel art and the native resolution is a bit small.
Title: Re: Tilemap flickering
Post by: unikronsoftware on April 15, 2014, 05:00:20 pm
You can snap it to the scaled resolution. If you snap it to the resolution of the final pixel (you can use Camera.ScreenToWorldPoint(Vector3(1,1,0)) to work out the size of a pixel, then it won't be blocky - it will be snapping to actual pixels.
Title: Re: Tilemap flickering
Post by: iSamurai on April 18, 2014, 02:36:54 pm
Hi, thanks for the reply.
Unfortunately I still couldn't get it right.
How I followed your method is like this:

pixelSize = Camera.main.ScreenToWorldPoint(new Vector3(1, 1, 0));

and how I used it is:

pos.x = Mathf.Round(pos.x / pixelSize.x) * pixelSize.x;

But it is still blocky.. Maybe I missed something?
However, I got your idea. I change the pos to Screen Space and round it to integer, and change it back to World Space, and it works fine. Thanks a lot :)