简体   繁体   English

如何在libgdx中的x轴上旋转图像?

[英]How can i rotate an image over its x axes in libgdx?

I'm trying to rotate an image over its x axes but its not working 我试图在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));

You can rotate your texture right when you draw it on the batch. 在批处理上绘制纹理时,可以正确旋转纹理。

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

So above is the exact code that you need to rotate your image in x-axis, y-axis or both. 因此,上面是您在x轴,y轴或两者中旋转图像所需的确切代码。

where : 其中:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM