2017-04-24 106 views
3

我試圖在其x軸旋轉的圖像,但它不工作如何在libgdx中的x軸上旋轉圖像?

Texture one = new Texture(Gdx.files.internal("img/one.jpg")); 
oneImg = new Image(one); 
oneImg.setOrigin(oneImg.getWidth()/2, oneImg.getHeight()/2); 
oneImg.setPosition(stage.getWidth()/2-32 , stage.getHeight()/2); 
oneImg.setScale(2f,2f); 
oneImg.addAction(rotateBy(360, 0.5f)); 
+0

在2D中,可以通過從1到-1在y方向上縮放和背面使用正確的(竇)內插 –

+0

模擬x軸旋轉可以請你告訴我一個簡單的代碼那實現了嗎? –

回答

1

當你畫它的批次您可以旋轉你的紋理權。

SpriteBatch.draw(textureRegion.getTexture(), x, y, originX, originY, width, height, scaleX, scaleY, rotation, srcX, srcX, srcWidth, srcHeight, false, false); 

所以上面是你需要在x軸,y軸或兩者上旋轉圖像的確切代碼。

其中:

x - the x-coordinate in screen space 
y - the y-coordinate in screen space 

originX - the x-coordinate of the scaling and rotation origin relative to the screen space coordinates 
originY - the y-coordinate of the scaling and rotation origin relative to the screen space coordinates 

width - the width in pixels 
height - the height in pixels 

scaleX - the scale of the rectangle around originX/originY in x 
scaleY - the scale of the rectangle around originX/originY in y 

rotation - the angle of counter clockwise rotation of the rectangle around originX/originY 

srcX - the x-coordinate in texel space 
srcY - the y-coordinate in texel space 

srcWidth - the source with in texels 
srcHeight - the source height in texels