java 如何使用 SpriteBatch 绘制方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14564291/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to use SpriteBatch draw method
提问by vishal
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)
What is the meaning of originX
, originY
, scaleX
, scaleY
, rotation
? Also can you please give me an example of their use?
originX
, originY
, scaleX
, scaleY
,是什么意思rotation
?另外你能给我举个例子说明它们的用法吗?
回答by jellyfication
Why don't you look into docs?
你为什么不看看文档?
As stated in docs, origin is bottom left corner, originX
, originY
are offsets from this origin.
For example if you want object rotate around his center, you will do this.
如文档中所述,原点是左下角originX
,originY
是与该原点的偏移量。例如,如果您希望对象围绕他的中心旋转,您可以这样做。
originX = width/2;
originY = height/2;
By specifing scaleX
, scaleY
, you scale the image, if you want to make Sprite 2x larger, you will set both scaleX and scaleY to number 2
.
通过指定scaleX
, scaleY
,您可以缩放图像,如果您想让 Sprite 变大 2 倍,您需要将 scaleX 和 scaleY 都设置为 number 2
。
rotation
specifies rotation around origin in degrees.
rotation
指定绕原点的旋转度数。
This code snippet draws texture rotated by 90 degrees around its center
此代码片段绘制围绕其中心旋转 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();
or take a look at tutorial here.
或在这里查看教程。