1
\$\begingroup\$

How can i control the speed of a tweening sprite? Here is the code:

in create ()

/*try tween*/
            w = Gdx.graphics.getWidth();
            h = Gdx.graphics.getHeight();

            texture = new Texture("nube_png_by_diieguiitoh-d4vhyzb.png");
            texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);

            sprite1 = new Sprite(texture);
            sprite1.setPosition(50,0.25f*h);

            Tween.registerAccessor(Sprite.class, new SpriteAccessor());
            manager1 = new TweenManager();
            Tween.to(sprite1,SpriteAccessor.POSITION_X,1000f) //** tween POSITION_X for a duration **//
                    .target(w-100) // ** final POSITION_X **//
                    .ease(TweenEquations.easeInOutQuad) //** easing equation **//
                    .repeat(10,1000f) //** ten more times **//
                    .start(manager1); //** start it
            startTime = TimeUtils.millis();
/*try tween*/

In render()

        batch.begin();

        delta = (TimeUtils.millis()-startTime)/1000; // **get time delta **//
        manager1.update(delta); //** update sprite1 **//
        sprite1.draw(batch);

        batch.end();
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

You don't. That defeats the purpose of a tween. A tween is supposed to control the speed itself using an easing function and giving it a total time. If you want to control the speed of an object, you'll have to give it a velocity yourself and update it through your normal game loop.

\$\endgroup\$
2
  • \$\begingroup\$ how about i adjust the delta time? \$\endgroup\$
    – hkguile
    Commented Oct 10, 2014 at 9:35
  • \$\begingroup\$ Sure, that's one way to slow it down or speed it up. \$\endgroup\$ Commented Oct 10, 2014 at 14:20

You must log in to answer this question.

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