- Home /
GUI on iPhone...GUI.DrawTexture or guiTexture.pixelInset ?
I started messing around with the HUD for my iPhone game, and after lots of researching, I tried 2 different ways of updating my HUD texture (it's a boost gauge which goes down as you use the boost).
The first method I tried is GUI.DrawTexture:
void OnGUI () {
float rectPosX = (Screen.width / 2) - (chargeFull.width / 2);
float rectPosY = chargeFull.height + (Screen.height / 1.1F);
float rectSizeX = boostPercentage * chargeFull.width;
float rectSizeY = chargeFull.height;
GUI.DrawTexture(new Rect(rectPosX, rectPosY, rectSizeX, rectSizeY), chargeFull, ScaleMode.ScaleAndCrop);
}
The second method I tried is through guiTexture.pixelInset:
void UpdateBoost () {
float boostPercentage = Mathf.Clamp01(boostCharge / maxBoost);
//print(boostPercentage);
// Store pixelInset in temporary variable to be able to change its values...
var pixelInsetX = chargeBar.pixelInset;
// Update boostGauge texture width based on boostPercentage left...
pixelInsetX.xMax = chargeBar.pixelInset.xMin + chargeBar.texture.width * boostPercentage;
chargeBar.pixelInset = pixelInsetX;
}
Both methods work as intended, it updates my HUD texture by shrinking it as boost goes down. But I'm not sure which one to use considering this is for iPhone...I have read that OnGUI() is expensive, so I'm leaning more towards not using it and going with guiTexture.pixelInset instead.
I just wanted some opinions on this matter from experienced iPhone devs...thanks in advance!
Your answer
Follow this Question
Related Questions
Fade script working but I can't 'see' it working? (Solved) 1 Answer
Better performance? GUITextures or Texture2D drawn in function OnGUI? 0 Answers
Is there an issue when playing a Movie Texture as a GUITexture? 1 Answer
Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer
Scale menu to fit webplayer with fullscreen on/off 0 Answers