Jump to content

calculo de animação spritesheet


cgm2k7

Recommended Posts

Boa tarde!
Estou criando um pequeno game 2d em directx11, estou na para de animar os sprite.
Veja mina duvida: 
Tenho uma folha de sprite com 18 quadros, 3 linha com 6 colunas.
Consigo fazer a animação de modo bem manual. Problema é que se precisar aumentar as colunas ou linhas preciso mudar todo  o código da animação.
Gostaria se alguém ai puder me ajudar  a fazer este código mais automático.

esse e o código:

[code=delphi]float *v = new float[m_NumRow];
    for (size_t i = 0; i < m_NumRow; i++)
    {
        v[i] = i*(1.0f/m_NumRow);
    }
    float t = 0,  k = 1.0f/m_NumRow;
    if (currentFrame >= m_NumCol)
    {
        t = v[1];
    }
    if (currentFrame >= (m_NumCol + m_NumCol))
    {
        t = v[2];
    }
    if (currentFrame < m_NumCol)
        t = v[0];

    m_vertices[0].uv.x = (float)(currentFrame) / m_NumCol;
    m_vertices[0].uv.y = t + k;

    m_vertices[1].uv.x = (float)(currentFrame) / m_NumCol;
    m_vertices[1].uv.y = t;  

    m_vertices[2].uv.x = (float)(currentFrame + 1.0f) / m_NumCol;
    m_vertices[2].uv.y = t;

    m_vertices[3].uv.x = (float)(currentFrame + 1.0f) / m_NumCol;
    m_vertices[3].uv.y = t + k;

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...