我在雪碧上调用draw,然后在SpriteBatch上调用draw来绘制相同的sprite。
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()调用?
发布于 2017-12-22 07:22:14
从您发布的代码中可以看出这有点棘手,但我认为您正在调用以下函数:
/** 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正在实现)。
https://stackoverflow.com/questions/47935168
复制相似问题