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
我檢查所有變量的值,這是問題。
OK病與F指定,我只是想浮動frameWidth =(浮動)( 1/NumFramesWide); \t \t float frameHeight =(float)(1/NumFramesTall);並沒有工作要麼 – WIllJBD 2012-08-11 00:46:15
同樣的問題,在該嘗試:整數除法第一,然後強制浮動。那裏是 – digitalbreed 2012-08-11 00:47:06
。謝謝。 – WIllJBD 2012-08-11 00:47:55