I’m creating a power bar that goes up and down for a mobile game. I need the power bar to increase and decrease at the same rate across all platforms for frame rate independence. I’ve been told to use Time.deltaTime, but the screen size seems to effect the rate. Here is some simple code that illustrates my dilemma:
var texture : Texture2D;
var progress : int = 0;
var speed : int = 100;
function Update ()
{
progress += Time.deltaTime * speed;
if(progress > Screen.width)
{
print ("End time is: " + Time.time);
}
}
function OnGUI()
{
GUI.DrawTexture(Rect(0,0, progress, 25), texture);
}
In this example, i’m drawing a texture from the left side of the screen to the right side. I want the end time (when the texture crosses the right side of the screen) to be the same no matter what screen size i’m at. Right now, if the screen size is small (about the size of an iPhone), the end time is around 4 seconds. If it’s larger (about the size of an iPad), the end time is about 11 seconds. I’m guessing a possible solution would be to create the speed variable according to the screen size - it seems to work with very minor variances in end times (less than 0.1), but I wanted to see if anyone else had any ideas/thoughts.