Hello Guest

Author Topic: Flickering Black Lines  (Read 6219 times)

blameMike

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
Flickering Black Lines
« on: September 19, 2013, 01:33:07 am »
I'm facing kind of a weird situation where my sprites seem to flicker when they stop moving. Black lines disappear and then reappear. I'm using a sprite collection and sprite animator on a GameObject with raycasters.

This video illustrates the issue. Any help would be greatly appreciated! Thanks in advance.

https://vimeo.com/74881319

JFBillingsley

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Flickering Black Lines
« Reply #1 on: September 19, 2013, 09:44:14 am »
That'd be because your (smooth-scrolling) camera is often at non-integer coordinates. This can make tris appear one pixel bigger/smaller than they would otherwise due to rounding.

Try rounding off your camera's (and sprites'!) position to integer coordinates. Be sure to store the "real", floating-point position, and set the transform's position to the rounded version of that.

Unless there's a better way of doing that that I don't know about :Va

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Flickering Black Lines
« Reply #2 on: September 19, 2013, 11:32:03 am »
That sounds pretty much the reason - another reason this could be more obvious than normally would be is your sprites arent being drawn 1:1 - this will likely cause issues with filtering and picking the correct pixel - you can try to avoid this by adding some padding or using premultiplied alpha.

Try JFBillingsley's suggestion first though. That will likely simply solve the problem straight away.

blameMike

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Flickering Black Lines
« Reply #3 on: September 19, 2013, 03:51:49 pm »
Thanks so much for the replies. I will give those a try, and report back.

blameMike

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Flickering Black Lines
« Reply #4 on: September 20, 2013, 05:19:47 pm »
If I round my camera coordinates I always get 0, and the camera doesn't following. I'm using a tk2d Camera, and this script to make it follow the character. Is there a better way to make it follow?


   void Update () {
      float yDelta = target.position.y - transform.position.y;
      float xDelta = target.position.x - transform.position.x;
      transform.Translate( Mathf.Round(xDelta * Time.deltaTime), Mathf.Round(yDelta * Time.deltaTime), 0.0f);
   }

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Flickering Black Lines
« Reply #5 on: September 20, 2013, 05:41:20 pm »
That probably won't work.
Assuming your tk2dCamera is set to pixels per meter, you should do something like this.

Code: [Select]
Vector3 cameraPosition = ...;

Vector3 SnapToPixel( Vector3 position ) {
   float ppm = tk2dcam.CameraSettings.orthographicPixelsPerMeter;
   position.x = Mathf.Round(  position.x * ppm ) / ppm;
   position.y = Mathf.Round( position.y * ppm ) / ppm;
   return position;
}

void Update() {
     delta = ...;
     cameraPosition = cameraPosition + delta * Time.deltaTime;
     transform.position = SnapToPixel( cameraPosition );
}

cameraPosition contains the floating point information, but the transform.,position always contains the snapped position.

blameMike

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Flickering Black Lines
« Reply #6 on: September 20, 2013, 06:08:20 pm »
Thanks so much. I'll give it a shot.  :)