-1

在我的 libGdx 项目中,我使用 createSprite() 从纹理图集创建了一个精灵。我想将精灵实现为旋转。我该怎么做?这是我的代码:

 reelSprite = atlas.createSprite("reel"); 

内部渲染():

for (Wall lWalls : leftWalls){
        reelSprite.setOrigin(lWalls.getX(), lWalls.getY());
        reelSprite.setRotation(180);

    batch.draw(reelSprite, lWalls.getX(), lWalls.getY());
    }

此代码不起作用。请告诉我我做错了什么。

4

3 回答 3

0
float rotate = 0;
rotate += (sprite.getRotation() - 40) * Gdx.graphics.getDeltaTime();
      if(Math.abs(rotate) > 10) // change the number to set the rotation power cap
            {
                rotate = -10;
            }
   sprite.rotate(rotate);
于 2016-12-02T21:17:39.947 回答
0

我改变了这样的代码......

for (Wall lWalls : leftWalls){
        reelSprite1.setPosition(lWalls.getX(), lWalls.getY());
        reelSprite1.setOrigin(reelSprite1.getWidth()/2,reelSprite1.getHeight()/2);
        reelSprite1.setRotation(180);
        reelSprite1.draw(batch);

然后它起作用了。

于 2016-12-05T09:56:53.983 回答
0

你应该在绘制精灵之前使用 setRotation :

https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/Sprite.html#setRotation-float-

甚至在设定的旋转点之前:

https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/Sprite.html#setOrigin-float-float-

于 2016-12-01T14:15:39.383 回答