Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

This is just speculation:

Maybe you forgot to call act() on your Stage that has all the Actors. Actions are updated per frame through the act() method on each Actor which is called by Stage's act().

public void render () {
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    stage.act(Gdx.graphics.getDeltaTime()); 
    stage.draw();
}

From https://code.google.com/p/libgdx/wiki/scene2d

Edit: Real problem was overriding act() without calling super.act() which updates list of Action as found in Actor class source.

share|improve this answer
    
Sorry, I call act right before draw. I should have added my update code... –  TM3P May 4 '13 at 16:10
1  
Ok, you may want to look at the source of Actor class since you're overriding act() which probably does more complex stuff than what you got there. Try calling super.act() first. –  XiaoChuan Yu May 4 '13 at 16:13
    
Thanks, that solved my problem! –  TM3P May 4 '13 at 16:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.