首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用SpriteBatch绘图方法

如何使用SpriteBatch绘图方法
EN

Stack Overflow用户
提问于 2013-01-28 22:34:03
回答 1查看 12K关注 0票数 1
代码语言:javascript
复制
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)

originXoriginYscaleXscaleYrotation是什么意思?另外,您能给我举一个使用它们的例子吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-28 23:13:40

你为什么不去调查一下docs呢?

正如文档中所述,原点是左下角,originXoriginY是该原点的偏移量。例如,如果您希望对象围绕其中心旋转,则可以执行此操作。

代码语言:javascript
复制
originX = width/2;
originY = height/2;

通过指定scaleXscaleY,你可以缩放图像,如果你想让雪碧图放大2倍,你需要将scaleX和scaleY都设置为数字2

rotation指定绕原点旋转(以度为单位)。

此代码片段绘制围绕其中心旋转90度的纹理

代码语言:javascript
复制
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

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14564291

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档