【问题标题】:Rotating sprite in java LibGDXjava LibGDX中的旋转精灵
【发布时间】:2014-09-02 14:28:08
【问题描述】:

有一个定义纹理的精灵的资产类,然后将精灵作为该纹理表,并带有表的坐标。这是我要旋转的精灵。 有人建议我使用 Sprite Batch 旋转它(它会旋转到我的触摸输入:

batch.draw(TextureRegion region,
                 float x,
                 float y,
                 float originX,
                 float originY,
                 float width,
                 float height,
                 float scaleX,
                 float scaleY,
                 float rotation)

我得到了错误:

SpriteBatch 类型中的方法draw(Texture, float, float, int, int, int, int) 不适用于参数(Sprite, int, int, int, int, int, int, int, float)

有没有一种方法可以将精灵投射到纹理或更好的旋转它的方法,它不起作用请帮忙!

【问题讨论】:

  • 您遇到此问题是因为您尝试将整数传递给期望浮点数的函数。调用函数时尝试将所有整数转换为浮点数。
  • @clearlyspam23 我试试这个 'game.batch.draw(FarmerAsset.upFarmer1, farmerX, farmerY, (float)85, (float)85, (float)170, (float)170, (float) )1, (float)angleDegrees); ' 但我仍然遇到同样的错误,这与使用 sprite oppesed to texture 无关吗?
  • 根据SpriteBatch docs,应该有一个需要TextureRegion的重载,根据Sprite docs,Sprites应该是TextureRegions,这样应该可以工作。在我看来,您可能在函数调用中缺少一个参数(您有 scaleX 但没有 scaleY)
  • @clearlyspam23 我的朋友谢谢你,你是个天才,如果你愿意,我很乐意接受你的回答

标签: java libgdx sprite


【解决方案1】:

您可以简单地使用 rotate(float degree) 。 设置精灵相对于当前旋转的旋转度数。

你必须在你的类的 render 方法中使用 rotate(float degree)。

Sprite Class documentation中给出

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多