2012-08-11 92 views
0

这是我用来飞过我的精灵表的方法。在对象类中,我跟踪信息并完成所有的循环,这基本上只需要分配纹理映射坐标。只有它似乎没有工作。但我登录的方式,我翻转行/列,它是正确循环。但我没有看到任何纹理。在所有。我错过了什么吗?为什么在将1除以2或4时返回0?

public void SetToAnimatedTexture(int NumFramesWide, int NumFramesTall, int CurrentRow, int CurrentColumn) { 
    /***************************************************************************************** 
    * This Assembles our Vertices in the correct spots by disassembling 
    * our custom rectangles corners, and adds animation. Call this after creating the meshRect 
    * *****************************************************************************************/ 

    float frameWidth = 1/NumFramesWide; 
    float frameHeight = 1/NumFramesTall; 

    float u1 = frameWidth*CurrentColumn; 
    float u2 = (frameWidth*CurrentColumn) + frameWidth; 
    float u3 = (frameWidth*CurrentColumn) + frameWidth; 
    float u4 = frameWidth*CurrentColumn; 

    float v1 = (frameHeight*CurrentRow) + frameHeight; 
    float v2 = (frameHeight*CurrentRow) + frameHeight; 
    float v3 = frameHeight*CurrentRow; 
    float v4 = frameHeight*CurrentRow; 

    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(4 * VERTEX_SIZE); 
    byteBuffer.order(ByteOrder.nativeOrder()); 
    vertices = byteBuffer.asFloatBuffer(); 

    float x1 = (float) rect.BottomLeftCorner.x; 
    float x2 = (float) rect.BottomRightCorner.x; 
    float x3 = (float) rect.TopRightCorner.x; 
    float x4 = (float) rect.TopLeftCorner.x; 

    float y1 = (float) rect.BottomLeftCorner.y; 
    float y2 = (float) rect.BottomRightCorner.y; 
    float y3 = (float) rect.TopRightCorner.y; 
    float y4 = (float) rect.TopLeftCorner.y; 

    vertices.put(new float[] { x1, y1, 1, 1, 1, 1, u1, v1, 
           x2, y2, 1, 1, 1, 1, u2, v2, 
           x3, y3, 1, 1, 1, 1, u3, v3, 
           x4, y4, 1, 1, 1, 1, u4, v4 }); 
          // x y r g b A u|s v|t 
          // x,y are coordinates 
          // rgba = color red green blue alpha 
          // u|s v|t = UV or ST texture coordinates 
    vertices.flip(); 

    byteBuffer = ByteBuffer.allocateDirect(6 * 2); 
    byteBuffer.order(ByteOrder.nativeOrder()); 
    indices = byteBuffer.asShortBuffer(); 
    indices.put(new short[] { 0, 1, 2, 
           2, 3, 0 }); 
    indices.flip(); 

} 

这是我为自己设置的框架的一部分。

好吧,通过做一些日志记录找出问题。这里这个权利是万阿英,蒋达清

float frameWidth = 1/NumFramesWide; 
    float frameHeight = 1/NumFramesTall; 

它返回值都为0。 它说

1/2=0 , 1/4=0 

我检查所有变量的值,这是问题。

回答

9

这是做整数除法第一,然后分配。由于两个1和NumFrames*是整数,你最终以0

您可以通过改变代码解决这个问题,以

float frameWidth = 1.f/NumFramesWide; 
float frameHeight = 1.f/NumFramesTall; 
+0

OK病与F指定,我只是想浮动frameWidth =(浮动)( 1/NumFramesWide); \t \t float frameHeight =(float)(1/NumFramesTall);并没有工作要么 – WIllJBD 2012-08-11 00:46:15

+0

同样的问题,在该尝试:整数除法第一,然后强制浮动。那里是 – digitalbreed 2012-08-11 00:47:06

+1

。谢谢。 – WIllJBD 2012-08-11 00:47:55

相关问题