Search code examples
libgdxspritetexture-atlas

Creating sprite from texture atlas


In my libGdx project,I created a sprite from texture atlas,using createSprite(). I want to implement the sprite as rotated. How can I do it?Here is my Code:

 reelSprite = atlas.createSprite("reel"); 

Inside render():

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

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

This code is not working.Please tell me what wrong I did.


Solution

  • I changed the code like this...

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

    then it worked.