2D Toolkit Forum
2D Toolkit => Support => Topic started by: blameMike 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
-
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
-
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.
-
Thanks so much for the replies. I will give those a try, and report back.
-
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);
}
-
That probably won't work.
Assuming your tk2dCamera is set to pixels per meter, you should do something like this.
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.
-
Thanks so much. I'll give it a shot. :)