Java 如何使用SpriteBatch绘图方法
originX,originY,scaleX,scaleY,rotation是什么意思?你能给我举一个使用它们的例子吗?你为什么不研究一下呢 如文档中所述,原点是左下角,originX、originY是从该原点的偏移量。 例如,如果希望对象围绕其中心旋转,则可以执行此操作Java 如何使用SpriteBatch绘图方法,java,libgdx,Java,Libgdx,originX,originY,scaleX,scaleY,rotation是什么意思?你能给我举一个使用它们的例子吗?你为什么不研究一下呢 如文档中所述,原点是左下角,originX、originY是从该原点的偏移量。 例如,如果希望对象围绕其中心旋转,则可以执行此操作 SpriteBatch batcher = new SpriteBatch(); batcher.draw(TextureRegion region, float x, fl
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)
通过指定scaleX、scaleY,可以缩放图像,如果要将Sprite放大2倍,可以将scaleX和scaleY都设置为数字2
旋转指定围绕原点的旋转(以度为单位)
此代码片段绘制围绕其中心旋转90度的纹理
或者看看教程。你为什么不看看呢
如文档中所述,原点是左下角,originX、originY是从该原点的偏移量。
例如,如果希望对象围绕其中心旋转,则可以执行此操作
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)
通过指定scaleX、scaleY,可以缩放图像,如果要将Sprite放大2倍,可以将scaleX和scaleY都设置为数字2
旋转指定围绕原点的旋转(以度为单位)
此代码片段绘制围绕其中心旋转90度的纹理
或者看一下教程。谢谢你们的帮助,我已经看过文档了,但我不知道如何使用draw方法旋转纹理。如果您有任何示例,请向我展示。Texture ball=new TextureGdx.files.internaldata/lion.png;TextureRegion ballRegion=新的TextureRegion球,0,0,64,64;batcher.DraillRegion,160-32/2,240-32/2,10,10,64,64,20,20,45;我想以90度的角度旋转纹理球。谢谢你们的帮助,我已经看过文档了,但我不知道如何使用draw方法旋转纹理。如果您有任何示例,请向我展示。Texture ball=new TextureGdx.files.internaldata/lion.png;TextureRegion ballRegion=新的TextureRegion球,0,0,64,64;batcher.DraillRegion,160-32/2,240-32/2,10,10,64,64,20,20,45;我想以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();