Archive 17/01/2023.

Sprite using ui->GetRoot()->CreateChild<Sprite>() rendering

Lumak

Why does Sprite created using ui->GetRoot()->CreateChild() renders on top of a Sprite created by new Sprite( context_ ) even though the new Sprite has higher priority?

My code sniplet:

    m_pSplashScreen = new Sprite( context_ );
    m_pSplashScreen->SetTexture( cache->GetResource<Texture2D>("Textures/black128.png") );
    m_pSplashScreen->SetSize( graphics->GetWidth(), graphics->GetHeight() );
    m_pSplashScreen->SetAlignment( HA_LEFT, VA_TOP );
    m_pSplashScreen->SetPriority( 100 );

    m_uiSplashTimerId = SDL_AddTimer( 3000, &Splash_TimerCallback, this );

    Sprite *pSpriteBackground = ui->GetRoot()->CreateChild<Sprite>();
    pSpriteBackground->SetTexture( cache->GetResource<Texture2D>("Textures/free-wallpaper-19.jpg") );
    pSpriteBackground->SetSize( graphics->GetWidth(), graphics->GetHeight() );
    pSpriteBackground->SetAlignment( HA_LEFT, VA_TOP );
    pSpriteBackground->SetPriority( -200 );

And m_pSplashScreen is never seen, however, if I construct the m_pSplashScreen using the ui->GetRoot()->CreateChild() method, it becomes visible.

Not sure what’s going on. Any help would be appreciated.

thebluefish

Not sure what you mean by the priority bit. Calling

new Sprite( context_ );

Will create a new Sprite object, but you do nothing to draw it. It needs to be added to the UI subsystem root (or another UIElement) so that the UI subsystem can handle drawing the sprite.

What happens when you create both sprites with ui->GetRoot()->CreateChild(); and then set their individual priority? It’s working for me when I add them both to the UI root.

Lumak

I figured it out but you beat me to it.
Thank you.