2dスプライトシートをアニメーション化したい。私は異なるフレームサイズのキャラクターアニメーションのスプライトシートを持っています。 1つのアニメーションに対して、1つのフレームに合わせて頂点をスケーリングし、アニメーションのためにテクスチャ位置を変更します。 1つのアニメーションではうまく機能しますが、別のフレームサイズのアニメーションに切り替えたり、頂点を拡大したり、フィッティングテクスチャを再度フィッティングしたりすると、テクスチャが伸縮してフィットしない副作用が発生します。 2つのアニメーションは非常に悪く見えます。OpenGL ESテクスチャマッピングオーバーフロー
私は、頂点サイズの変更のためだと思います。だから私の考えは、固定頂点サイズを持ち、それを完全な頂点(すべてのアニメーションの高さが固定されています)に合わせずにフィットさせることです。
多分画像が役立ちますので、私は1を作成しました:ここimg http://oi44.tinypic.com/14l09hk.jpg
は私のコードですが、それは十分にあると思います:
public boolean nextFrame() {
float textureWidth = textureMap()[currentAnimation][0];
float frameCount = textureMap()[currentAnimation][1];
float frameWidth = textureWidth/frameCount;
if (loop) {
if (currentFrame == frameCount)
currentFrame = 0;
} else {
if (currentFrame == frameCount) {
setAnimation(AnimationConstants.IDLE);
loop = true;
return false;
}
}
float x_left = (float) currentFrame * frameWidth/textureWidth;
float x_right = (float) (currentFrame * frameWidth + frameWidth)
/textureWidth;
texture[0] = x_left; // top left x
texture[1] = 1.0f; // top left y
texture[2] = x_left; // bottom left x
texture[3] = 0.0f; // bottom left y
texture[4] = x_right; // top right x
texture[5] = 1.0f; // top right y
texture[6] = x_right; // bottom right x
texture[7] = 0.0f; // bottom right y
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(texture.length * 4);
byteBuffer.order(ByteOrder.nativeOrder());
textureBuffer = byteBuffer.asFloatBuffer();
textureBuffer.put(texture);
textureBuffer.position(0);
currentFrame++;
return true;
}
private void newVertex() {
float textureWidth = textureMap()[currentAnimation][0];
float frameCount = textureMap()[currentAnimation][1];
float frameWidth = textureWidth/frameCount;
float width = (float) frameWidth/(float) frameHeight;
vertices[0] = pos_x; // bottom left x
vertices[1] = pos_y; // bottom left y
vertices[3] = pos_x; // top left x
vertices[4] = pos_y + (1.0f * scale); // top left y
vertices[6] = pos_x + (width * scale); // bottom right x
vertices[7] = pos_y; // bottom right y
vertices[9] = pos_x + (width * scale); // top right x
vertices[10] = pos_y + (1.0f * scale); // top right y
// z values
vertices[2] = -0.2f; // bottom left z
vertices[5] = -0.2f; // top left z
vertices[8] = -0.2f; // bottom right z
vertices[11] = -0.2f; // top right z
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(vertices.length * 4);
byteBuffer.order(ByteOrder.nativeOrder());
vertexBuffer = byteBuffer.asFloatBuffer();
vertexBuffer.put(vertices);
vertexBuffer.position(0);
}
ので、すべての新しいアニメーションのために、私は)(newVertexを呼び出します。
したがって、状況2が必要ですが、状況1のコードを示していますか? – mbeckish
ボキャブラリーのちょっとしたポイント。あなたが頂点と呼ぶものは、実際には頂点バッファオブジェクト、すなわちジオメトリです。真の頂点は空間点であり、定義上はサイズを持たない。 – rockeye
@mkbeckish right、私は状況2が欲しいと思います。私はopenglにとって非常に新しいので、上のコードは私のコードの状況を示すために作られた最初のコードです。おそらく全体のコンセプトが間違っているので、わかりません。 –