2009-03-01 33 views

回答

1

使用像OpenGL這樣的現代3D API的sprite sheeting的典型方法是使用紋理座標來解決單個紋理的不同部分。雖然你可以分割它,但是使用紋理座標對資源更友好。

例如,如果你有一個簡單的精靈片具有水平3幀,每個32個像素×32個像素(用於96x32的總大小),則可以使用以下代碼來繪製第三幀:

// I assume you have bound your source texture 
// This is the U coordinate's origin in texture space 
float xStart = 64.0f/96.0f; 

// This is one frame width in texture space 
float xIncrement = 32.0f/96.0f; 

glBegin(GL_QUADS); 
    glTexCoord2f(xStart, 0); 
    glVertex2f(-16.0f, 16.0f); 

    glTexCoord2f(xStart, 1.0f); 
    glVertex2f(-16.0f, -16.0f); 

    glTexCoord2f(xStart + xIncrement, 0); 
    glVertex2f(16.0f, 16.0f); 

    glTexCoord2f(xStart + xIncrement, 1.0f); 
    glVertex2f(16.0f, -16.0f); 
glEnd(); 
+0

是的,但我需要有身高。 – William 2009-03-01 05:05:19

相關問題