SpriteBatch batcher = new SpriteBatch();
batcher.draw(TextureRegion region,
float x,
float y,
float originX,
float originY,
float width,
float height,
float scaleX,
float scaleY,
float rotation)originX,originY,scaleX,scaleY,rotation是什么意思?另外,您能给我举一个使用它们的例子吗?
发布于 2013-01-28 23:13:40
你为什么不去调查一下docs呢?
正如文档中所述,原点是左下角,originX、originY是该原点的偏移量。例如,如果您希望对象围绕其中心旋转,则可以执行此操作。
originX = width/2;
originY = height/2;通过指定scaleX,scaleY,你可以缩放图像,如果你想让雪碧图放大2倍,你需要将scaleX和scaleY都设置为数字2。
rotation指定绕原点旋转(以度为单位)。
此代码片段绘制围绕其中心旋转90度的纹理
SpriteBatch batch = new SpriteBatch();
Texture texture = new Texture(Gdx.files.internal("data/libgdx.png"));
texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
int textureWidth = texture.getWidth();
int textureHeight = texture.getHeight();
float rotationAngle = 90f;
TextureRegion region = new TextureRegion(texture, 0, 0, textureWidth, textureHeight);
batch.begin();
batch.draw(region, 0, 0, textureWidth / 2f, textureHeight / 2f, textureWidth, textureHeight, 1, 1, rotationAngle, false);
batch.end();或者看看tutorial here。
https://stackoverflow.com/questions/14564291
复制相似问题