2
\$\begingroup\$

enter image description here

I want to rotate my image on touch but it never applies action, I'm using RotateToAction to achieve this.

class actorCark extends Actor
{
    Texture texture;
    Sprite sprite;
    Global g;
    GetActorByName a;
    public actorCark()
    {
        ses=new sesler();
        g=new Global();
        a=new GetActorByName();
        sr=new soruSor();
        texture=new Texture(Gdx.files.internal("images/carkifelek.png"));
        sprite=new Sprite(texture);
        setBounds(Global.screen_width / 2 - Global.screen_height * 0.9F * sprite.getTexture().getWidth() / sprite.getTexture().getHeight() / 2, Global.screen_height / 2 - Global.screen_height * 0.9F / 2, Global.screen_height * 0.9F * sprite.getTexture().getWidth() / sprite.getTexture().getHeight(), Global.screen_height * 0.9F);
        setTouchable(Touchable.enabled);
        addListener(new InputListener() {
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int buttons) {
                clearActions();
                RotateToAction rotateToAction=new RotateToAction();
                rotateToAction.setRotation(360);
                rotateToAction.setDuration(2);
                addAction(rotateToAction);
                dondur();
                sesler.donmeS.play();
                return true;
            }
        });
    }
    @Override
    public void act(float delta) {
        super.act(delta);
    }
    public void draw(Batch batch, float alpha)
    {
        sprite.getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
        sprite.setBounds(Global.screen_width / 2 - Global.screen_height * 0.9F * sprite.getTexture().getWidth() / sprite.getTexture().getHeight() / 2, Global.screen_height / 2 - Global.screen_height * 0.9F / 2, Global.screen_height * 0.9F * sprite.getTexture().getWidth() / sprite.getTexture().getHeight(), Global.screen_height * 0.9F);
        sprite.setOrigin(sprite.getWidth() / 2, sprite.getHeight() / 2);
        sprite.draw(batch);
    }
}
\$\endgroup\$
3
  • \$\begingroup\$ do you call stage.act() in your main game loop? \$\endgroup\$ Apr 4, 2016 at 16:20
  • \$\begingroup\$ stage2.act(Gdx.graphics.getDeltaTime()); I am sure I do call it \$\endgroup\$ Apr 4, 2016 at 16:25
  • \$\begingroup\$ other cand of actions like moveToAction are working butr only rotate action doesnt works \$\endgroup\$ Apr 4, 2016 at 16:27

1 Answer 1

0
\$\begingroup\$

It seems that you are rotating your actor with the rotateTo action, but your sprite, which is doing the actual drawing, knows nothing about the actor's rotation. Try sprite.setRotation(this.getRotation()) in your draw() code.

\$\endgroup\$
1
  • \$\begingroup\$ I do yes it works but as you can see in the image I added to my post, I need to use some animation to make wheel rotate \$\endgroup\$ Apr 4, 2016 at 17:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .