Archive 17/01/2023.

Animated sprite 2D and loading screen

Cpl.Bator

Hello everybody, in first, thank you for this amazing engine !

i’ve got a some question , i want to continue my old-game with your engine ( youtube.com/watch?v=zbCcQOPXzmI )
but , i’m from SFML , and i use spritesheet animation without third party tool.

  • What is the way for use spritesheet animation without any external tool ?

I use a “custom” ressource manager ( with sfml ) for load / get resource , with my resource manager i can load them in separate thread and i can display a beautiful load screeen.

  • what is the good way for doing the same result with urho3D ?

In advance , thanks.

1vanK

I use this code for animating UI Sprite (not Sprite2D):

[code]void UIManager::StopAnimation(Sprite* element)
{
element->SetAttributeAnimationTime(“Image Rect”, 0.0f);
element->SetAttributeAnimationSpeed(“Image Rect”, 0.0f);
}

void UIManager::StartAnimation(Sprite* element)
{
element->SetAttributeAnimationSpeed(“Image Rect”, 1.0f);
}

void UIManager::AddAnimation(Sprite* element, const char* textureName, int frameWidth, int frameHeight,
int totalNumFrames, int maxColumns, float delay)
{
element->SetTexture(CACHE->GetResource(textureName));
element->SetBlendMode(BLEND_ALPHA);
element->SetSize(frameWidth, frameHeight); // Sprite size on screen.

SharedPtr<ValueAnimation> animation(new ValueAnimation(context_));
float time = 0.0f;

for (int i = 0; i < totalNumFrames; i++)
{
    int row = i / maxColumns;
    int col = i % maxColumns;
    IntRect rect(col * frameWidth, row * frameHeight, (col + 1) * frameWidth, (row + 1) * frameHeight);
    animation->SetKeyFrame(time, rect);
    time += delay;
}

// At the end again show firs frame
animation->SetKeyFrame(time, IntRect(0, 0, frameWidth, frameHeight));

animation->SetInterpolationMethod(IM_NONE);
element->SetAttributeAnimation("Image Rect", animation);

}
[/code]

Using:

    auto animatedSprite = UI_ROOT->CreateChild<Sprite>();
    AddAnimation(animatedSprite, "Textures/AnimExclam.png", 20, 64, 20, 10, 1.0f / 24);

I have not tried, but most likely this approach will work for Sprite2D.

Cpl.Bator

thank you, i will try this method soon.