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

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

4

1 回答 1

9

它首先进行整数除法,然后进行赋值。因为 1 和NumFrames*都是整数,所以你最终得到 0。

您可以通过将代码更改为来解决此问题

float frameWidth = 1.f/NumFramesWide;
float frameHeight = 1.f/NumFramesTall;
于 2012-08-11T00:45:33.997 回答