I have this code for rendering a sprite, retrieved from a TextureAtlas
public class SpriteActor extends Actor {
private Sprite sprite;
public SpriteActor(TextureAtlas atlas, String spriteName) {
sprite = atlas.createSprite(spriteName);
this.setWidth(sprite.getWidth());
this.setHeight(sprite.getHeight());
this.setBounds(0, 0, this.getWidth(), this.getHeight());
}
@Override
public void act(float delta) {
sprite.setPosition(this.getX(), this.getY());
sprite.setOrigin(this.getOriginX(), this.getOriginY());
sprite.setRotation(this.getRotation());
sprite.setScale(this.getScaleX(), this.getScaleY());
}
@Override
public void draw(SpriteBatch batch, float parentAlpha) {
Color color = new Color(this.getColor().r, this.getColor().g,
this.getColor().b, this.getColor().a * parentAlpha);
batch.setColor(color);
sprite.setColor(color);
sprite.draw(batch);
}
}
EDIT: Using actions with a Image actor in the same stage works, It's only my actor that doesn't
When I set the transparency like this : actor.setColor(1, 1, 1, 0.5f);
I can see the sprite becoming half transparent; or, if I set the position manually (actor.setPosition(0, 30);
) I see the sprite to the correct position; but if I try to use actions (import static com.badlogic.gdx.scenes.scene2d.actions.Actions.*;
[...] actor.addAction(fadeIn(3)
or actor.addAction(forever(rotateBy(45), delay(1))
) they just do nothing.
Do I need to implement something to have predefined actions working on my code? Or what do I need to make this code work?