Hi,
I am making a side scrolling game in NGUI & I am attaching background one after another. But when the new background is added it flickers the screen for a sec & then it works fine. I tested the game in run mode by pausing the game & then moving game frame by frame. I realized that the new background transform position getting set at 0 for X,Y,Z. & then it takes the position where it needs to set.
How can i resolve this issue. Please check the below mentioned code
public class AddBg:MonoBehaviour
{
float main mainBgCounter;
public GameObject mainBg;
public void AddMainBg()
{
Vector2 newPos = GetMainBgPos();
mainBg = Resources.Load("mainBackground") as GameObject;
mainBg.name = "MainBackground" + mainBgCounter;
// mainBg.transform.position = Vector2.zero;
Debug.Log("Maing bg new pos " + newPos);
mainBg.transform.localPosition = newPos;
NGUITools.AddChild(mainBackground, mainBg);
mainBgCounter++;
}
public Vector2 GetMainBgPos()
{
Vector2 newPos;
int childCount = mainBackground.transform.childCount;
if (childCount > 0)
{
Transform lastChild = mainBackground.transform.GetChild(childCount - 1);
newPos = new Vector2((lastChild.localPosition.x + mainBgWidth), 0);
}
else
{
leftx = (stageWidth - bgWidth) / 2;
newPos = new Vector2(leftx, 0);
}
return newPos;
}
}