我如何在libgdx中的x轴上旋转图像? [英] How can i rotate an image over its x axes in libgdx?

查看:64
本文介绍了我如何在libgdx中的x轴上旋转图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在x轴上旋转图像,但是它不起作用

I'm trying to rotate an image over its x axes but its not working

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);

因此,上面是在x轴或y轴或同时在这两个方向上旋转图像所需的确切代码.

So above is the exact code that you need to rotate your image in x-axis, y-axis or both.

其中:

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

这篇关于我如何在libgdx中的x轴上旋转图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆