2012-05-12 53 views
1

我正在讀這本名爲Android的初級遊戲。如何讓圖像旋轉看起來乾淨? Android GL ES

在它在SpriteBatcher類下面的方法的書......

public void drawSprite(float x, float y, float width, float height, float angle, TextureRegion region) { 
    float halfWidth = width/2; 
    float halfHeight = height/2; 

    float rad = angle * Vector2.TO_RADIANS; 
    float cos = FloatMath.cos(rad); 
    float sin = FloatMath.sin(rad); 

    float x1 = -halfWidth * cos - (-halfHeight) * sin; 
    float y1 = -halfWidth * sin + (-halfHeight) * cos; 
    float x2 = halfWidth * cos - (-halfHeight) * sin; 
    float y2 = halfWidth * sin + (-halfHeight) * cos; 
    float x3 = halfWidth * cos - halfHeight * sin; 
    float y3 = halfWidth * sin + halfHeight * cos; 
    float x4 = -halfWidth * cos - halfHeight * sin; 
    float y4 = -halfWidth * sin + halfHeight * cos; 

    x1 += x; 
    y1 += y; 
    x2 += x; 
    y2 += y; 
    x3 += x; 
    y3 += y; 
    x4 += x; 
    y4 += y; 

    verticesBuffer[bufferIndex++] = x1; 
    verticesBuffer[bufferIndex++] = y1; 
    verticesBuffer[bufferIndex++] = region.u1; 
    verticesBuffer[bufferIndex++] = region.v2; 

    verticesBuffer[bufferIndex++] = x2; 
    verticesBuffer[bufferIndex++] = y2; 
    verticesBuffer[bufferIndex++] = region.u2; 
    verticesBuffer[bufferIndex++] = region.v2; 

    verticesBuffer[bufferIndex++] = x3; 
    verticesBuffer[bufferIndex++] = y3; 
    verticesBuffer[bufferIndex++] = region.u2; 
    verticesBuffer[bufferIndex++] = region.v1; 

    verticesBuffer[bufferIndex++] = x4; 
    verticesBuffer[bufferIndex++] = y4; 
    verticesBuffer[bufferIndex++] = region.u1; 
    verticesBuffer[bufferIndex++] = region.v1; 

    numSprites++; 
} 

我的問題是你如何順利下方轉動像一個圖像,使圖像不要」中的臺詞看起來像素化?

我確實擁有合適大小和DPI的圖像,並且在旋轉之前看起來很棒,但是當它旋轉時,線條的邊緣看起來並不那麼棒。

enter image description here

回答

2

你可以嘗試使用線性採樣,而不是NEAREST,雖然這是我很難沒有看到問題的照片,或者看到你的紋理創建代碼猜測更多。

+0

拍攝了一個屏幕截圖,而不是將一些隨機圖像從互聯網上關聯到......看看飛機的線條是如此...蹩腳? – Zeveso

+0

是的一種鋸齒狀。你使用了什麼樣的抽樣,你可以放置你的紋理創建代碼?一些反鋸齒也可能會有所幫助,但我不知道具體的代碼。 – Tim

+0

我在哪裏可以閱讀有關線性取樣的更多信息,以便我可以應用這些?據我所知,我沒有使用任何特定類型的抽樣。我用來學習的項目的代碼在這裏:http://beginning-android-games.googlecode.com/svn/trunk/ch09-jumper/ – Zeveso