- Home /
Scrolling backgrounds cause lag on android
Hello there.
Yesterday I was very happy when I found out how to make Android on screen controls work. After that I realised the game is lagging on Android device (Samsung Galaxy Tab 2). I know it's an old device, but c'mon guys, my game is an endless runner done in pixel art. I remember that I played San Andreas on that device.
Let's get to the topic. I turned off things one by one and I found out that the lag is caused mostly by Scrolling Backgrounds and texture/platform that I run on. There are 4 of them and they are PNG. 3 Backgrounds and one texture. Here is the teaser of my game, you can see all backgrounds and the texture. [MEDIA=youtube]HnFm7Ypw7ec[/MEDIA]
This is the script that I use to scroll them.
[code] using UnityEngine; using System.Collections;
public class ScrollScript : MonoBehaviour { private Material currentMaterial; public float scrollSpeed; private float offset;
void Start (){
currentMaterial = GetComponent<Renderer>().material;
}
// Update is called once per frame
void FixedUpdate () {
offset += scrollSpeed * Time.deltaTime;
offset = offset % 1.0f;
currentMaterial.mainTextureOffset = new Vector2(offset,0);
}
}
[/code]
Is there anything that I can do to improve their performance ? If you need anything else I can provide you with it.
Thanks in advance !
Your answer
![](https://koobas.hobune.stream/wayback/20220612061317im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Scrolling Background 1 Answer
2D camera panning and can't click UI buttons 0 Answers
How to feed background less image sequence to Unity for 2D game? 2 Answers
Animation = Trasnslate Speed 2 Answers
Making background move and loop 0 Answers