从纹理图集创建精灵

Creating sprite from texture atlas

在我的 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());
    }

这段代码不是working.Please告诉我我做错了什么。

您应该在绘制精灵之前使用 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-

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);

我把代码改成这样...

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

然后成功了。