SharedPtr<Sprite> gameLogo; //defined in class MainScreen
The button becomes vague after adding unused function CreateLogo, without method CreateLogo() the button shows clearly. Really weird.
void MainMenuScreen::CreateLogo()
{
// Get logo texture
ResourceCache* cache = GetSubsystem<ResourceCache>();
Texture2D* logoTexture = cache->GetResource<Texture2D>("Textures/FishBoneLogo.png");
if (!logoTexture)
return;
// Create logo sprite and add to the UI layout
gameLogo = parent->CreateChild<Sprite>();
// Set logo sprite texture
gameLogo->SetTexture(logoTexture);
int textureWidth = logoTexture->GetWidth();
int textureHeight = logoTexture->GetHeight();
// Set logo sprite scale
gameLogo->SetScale(256.0f / textureWidth);
// Set logo sprite size
gameLogo->SetSize(textureWidth, textureHeight);
// Set logo sprite hot spot
//gameLogo->SetHotSpot(textureWidth, textureHeight);
Graphics* graphics = GetSubsystem<Graphics>();
int x = graphics->GetWidth()/2 - 256/2;
int y = int(textureHeight * gameLogo->GetScale().y_);
gameLogo->SetPosition(x, y);
// Set logo sprite alignment
//gameLogo->SetAlignment(HA_CENTER, VA_TOP);
//gameLogo->SetPosition(128, 256);
// Make logo not fully opaque to show the scene underneath
gameLogo->SetOpacity(0.9f);
// Set a low priority for the logo so that other UI elements can be drawn on top
gameLogo->SetPriority(-100);
}
screen showing well-rendered button:
vague buttons: