1
\$\begingroup\$

In my GameClass, I called the Stage.act and Stage.draw methods in the right order accordingly.

I have actions set up so that the actor fades in/fades out, bounces down/up, and also rotate, like so:

Label.LabelStyle font = new Label.LabelStyle(new BitmapFont(), Color.BLACK);

    Table table = new Table();
    table.center();
    table.setFillParent(true);

    Label playLabel = new Label("Text", font);

    Action fade = new SequenceAction(Actions.fadeOut(1), Actions.fadeIn(1));
    Action size = new SequenceAction(Actions.sizeBy(-20,-30,1), Actions.sizeBy(10,20,1));
    Action rotate = new SequenceAction(Actions.rotateBy(20), Actions.rotateBy(-40));

    ParallelAction pa = new ParallelAction(fade, size, rotate);

    playLabel.addAction(Actions.repeat(RepeatAction.FOREVER, pa));

    table.add(playLabel).expandX();
    table.row();

    stage.addActor(table);

The thing is, everything works except for the rotate method.

Similarly, I have similar problem when I use an Actor with Texture regions.

This is an example from another class.

public ReadyText () {
    cam = GameClass.cam;
    viewport = GameClass.viewport;
    cam.setToOrtho(true, viewport.getWorldWidth(), viewport.getWorldHeight());
    region = new TextureRegion(GameAssetLoader.Ready);
    this.setX(28);
    this.setY(165);
    this.setWidth(80);
    this.setHeight(30);

    //fade = Actions.sequence(Actions.fadeOut(1), Actions.fadeIn(1));
    Action rotate = Actions.sequence(Actions.rotateBy(80, 1), Actions.rotateBy(-90,1));
    Action resize = Actions.sequence(Actions.sizeBy(10, 5,1), Actions.sizeBy(-10,-5,1));


    ParallelAction pa = new ParallelAction(rotate, resize);

    addAction(Actions.repeat(RepeatAction.FOREVER, pa));


}

@Override
public void draw(Batch batch, float parentAlpha) {
    super.draw(batch, parentAlpha);

    batch = GameClass.batch;
    batch.setProjectionMatrix(GameClass.cam.combined);
    batch.draw(region, this.getX(), this.getY(), this.getWidth(), this.getHeight());


}

In this example, the "sizeBy" method works fine. But for some reason, it will not rotate. I commented out the "fade in/fade out" line; it also wasn't working either.

I know people will usually use an Image Actor instead, which makes sense, but I don't think it explains why the rotation won't work, or at the very least, why the Label didn't rotate either.

\$\endgroup\$
1
\$\begingroup\$

You need to draw you actor with a method that handle rotation

void draw(TextureRegion region,
      float x,
      float y,
      float originX,
      float originY,
      float width,
      float height,
      float scaleX,
      float scaleY,
      float rotation)

And for alpha actions: (this myActor draw method)

batch.begin();

// Store old batch alpha
temp = batch.getColor();

// Set new alpha to the batch
batch.setColor(new Color(temp.r, temp.g, temp.b, actorAlpha));

// Draw your actor
batch.draw(texture, getX(), getY(), getOriginX(), getOriginY(), texture.getRegionWidth(), texture.getRegionHeight(), 1, 1, getRotation());

// Restore old batch color
batch.setColor(temp);

batch.end();

Where temp is a Color.

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ Hmm okay I see now. What about the fade method? Does that involve using the parentAlpha or something? \$\endgroup\$ – Erick Adam Jan 29 '18 at 17:24
  • \$\begingroup\$ Exactly. You have to use parent alpha. You can even set the batch alpha to actor.alpha before drawing it and then set back the batch alpha to his old value before drawing other things. \$\endgroup\$ – Sebastien Servouze Jan 29 '18 at 17:55
  • \$\begingroup\$ I managed to get the alpha and scale working. But I'm confused about the fade. How do I use the parentAlpha? I've seen some posts saying that it needs to be multiplied to some other alpha. I do't get it. \$\endgroup\$ – Erick Adam Jan 29 '18 at 22:20
  • \$\begingroup\$ I edited my post so to implement it \$\endgroup\$ – Sebastien Servouze Jan 29 '18 at 22:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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