首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使SpriteBatch.draw()与Sprite.draw()等效?

如何使SpriteBatch.draw()与Sprite.draw()等效?
EN

Stack Overflow用户
提问于 2017-12-22 02:27:41
回答 1查看 84关注 0票数 0

我在雪碧上调用draw,然后在SpriteBatch上调用draw来绘制相同的sprite。

代码语言:javascript
复制
target.sprite.draw(game.batch);

game.batch.draw(target.sprite, target.sprite.getX(), target.sprite.getY(), 
                target.sprite.getOriginX(), target.sprite.getOriginY(),
                target.sprite.getWidth(), target.sprite.getHeight(),
                target.sprite.getScaleX(), target.sprite.getScaleY(),
                target.sprite.getRotation(), false);

..。但是,第二次调用与第一次调用相比,以90度的角度绘制了雪碧。当我减去90度以进行补偿时,精灵不会对齐,因为它们相对于屏幕是围绕相同的点旋转,但相对于它们自己则是不同的点(用SpriteBatch.draw()调用绘制的点是围绕用Sprite.draw()绘制的原点旋转的)。

如何进行等效的Sprite.Batch.draw()调用?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-12-22 07:22:14

从您发布的代码中可以看出这有点棘手,但我认为您正在调用以下函数:

代码语言:javascript
复制
/** Draws a rectangle with the texture coordinates rotated 90 degrees. The bottom left corner at x,y and stretching the region
 * to cover the given width and height. The rectangle is offset by originX, originY relative to the origin. Scale specifies the
 * scaling factor by which the rectangle should be scaled around originX, originY. Rotation specifies the angle of counter
 * clockwise rotation of the rectangle around originX, originY.
 * @param clockwise If true, the texture coordinates are rotated 90 degrees clockwise. If false, they are rotated 90 degrees
 *           counter clockwise. */
public void draw (TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation, boolean clockwise);

这里要注意的关键是,第四个和第五个参数不是要旋转的原点,而是来自原点的偏移量。如果希望该功能与sprite.draw()匹配,则应将0作为originX和originY传递。

如果您想避免90*旋转(这似乎是有意的;我认为这可能是为了使您可以将0度或弧度定义为“向上”而不是“正确”,如果这是合理的话),则应该使用该函数的重载版本,它省略了最后一个参数(boolean clockwise)。

所有这些都可以在libGDX的 interface源代码中找到( SpriteBatch正在实现)。

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

https://stackoverflow.com/questions/47935168

复制
相关文章

相似问题

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