Laggy movement of camera on a 2D game

Hi,

I have performance issues with a 2D game that is supposed to be very simple and trivial: the scene is pre-built with 200 sprites (512*512 png, max size defined to 512, and in compress mode) stacked horizontally next to each other. See screenshot to better illustrate.
Now, I’m trying to do a simple thing - move a camera on a const speed across all these images and for some reason on mobile it has some lagginess - once in a couple of seconds, the camera ‘jumps’ ahead, making it look very bad. But I want smooth movement.

The actual movement is implemented that way:
transform.position = new Vector3 (transform.position.x + SpaceshipScript.FlyHorizontalSpeed * Time.deltaTime, 0, -10);

I think I’ve tried everything so far - I put only 10 sprites next to each other, replace with jpg, tried with transparent/non transparent background, made all the prefabs static, removed all polygons, removed all menus, but it is still laggy! It seems like a very trivial behavior to achieve and I can’t get it right!

Could really use some experts tips here. Oh - I don’t know how to measure frame rate on Android, but on the editor it is around 2000.

Please helpppppppppppp !

Thanks,
Noam

try smoothing the vector3 with one of these

transform.position = Vector3.SmoothDamp (transform.position, targetPosition, ref velocity, smoothTime);
or
transform.position = Vector3.Lerp (transform.position, CamTargetPosition, smoothing * Time.deltaTime);

just noticed you said constant, as in a scrolling camera.

Try using transform.Translate instead of transform.position

something like
transform.Translate = Vector3 (movementRate * Time.deltaTime, 0, 0);

But if the SpaceshipScript.FlyHorizontalSpeed is so the camera follows the player then use a smoothdamp or lerp as above

Also, for a simple fps check on device have a look here

Time.deltaTime returns the time since last frame so 1/Time.deltaTime would return the frame rate.

1 Like