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);
}
I have already set DefaultStyle for UI ROOT. The pasted code is not referenced anywhere in the project. Removing the unused code the button rendered clearly.
Right. So the data required for default UI style is there. The typical reason where UI buttons show different textures is because the default UI style is yet set. Be sure that the default UI style is set before creating any UI elements - follow the 02_HelloGUI example. Better yet, modify and work with the sample code.
Yeah, that’s weird. I see nothing wrong with what you wrote that’ll cause your UI elements to lose texture.
It’s as if there’s function/data misalignment in linking caused by partial rebuild of the Urho3Dlib due to some change in its components or library. I’d suggest doing a clean rebuild of the build tree and your project, but you mentioned 02 sample works properly, so I don’t know if it’ll help.