Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tween composition. #27

Open
marcusx2 opened this issue Nov 24, 2021 · 8 comments
Open

tween composition. #27

marcusx2 opened this issue Nov 24, 2021 · 8 comments

Comments

@marcusx2
Copy link

Please see Phaser3's timeline. It's possible to chain tweens. I find it very useful and much easier to work with when you intend that all of your tweens be a single animation in sequence.

Don't confuse with my timeline request.

@marcusx2 marcusx2 changed the title tween composition tween chaining. Nov 24, 2021
@yaustar
Copy link
Collaborator

yaustar commented Nov 24, 2021

Is not possible to chain tweens at the moment? Or is this something different?

@marcusx2 marcusx2 changed the title tween chaining. tween composition. Nov 24, 2021
@marcusx2
Copy link
Author

I think I made a misleading title, didn't explain myself well. Yes, I can chain tweens as it is, but I'd like to have a single entity that can register all tweens and play them as a single animation.

@yaustar
Copy link
Collaborator

yaustar commented Nov 24, 2021

I'm not sure if understand the difference here. You can chain the tweens together then play at a later stage in the code

@yaustar
Copy link
Collaborator

yaustar commented Nov 24, 2021

eg

var tween = app.tween(color).to(new pc.Color(0, 1, 1), 1, pc.Linear).to(new pc.Color(0, 1, 0), 1, pc.Linear);

// Later in code
tween.start();

@marcusx2
Copy link
Author

marcusx2 commented Nov 24, 2021

Oh....wonderful. My bad. This implementation is better than Phaser3's.

@yaustar
Copy link
Collaborator

yaustar commented Nov 24, 2021

Actually, I think I'm wrong in this. Tweens can't be chained in a quick test. The methods can but not the tween.

@yaustar yaustar reopened this Nov 24, 2021
@marcusx2
Copy link
Author

Oh. Ok lol. Being able to chain them would be cool.

@yaustar
Copy link
Collaborator

yaustar commented Nov 24, 2021

A current workaround is to do the following which is not great syntactically:

var OpacityTween = pc.createScript('opacityTween');

// initialize code called once per entity
OpacityTween.prototype.initialize = function() {
    var entity = this.entity;
    this.tween = entity.tween(entity.element)
        .to({opacity: 0, width: 200, height: 100}, 0.5, pc.Linear)
        .on('complete', function () {
            entity.tween(entity.element).to({opacity: 0.5, width: 400, height: 200}, 4, pc.CubicIn).start()
                .on('complete', function() {
                    entity.enabled = false;
                });
        });
};

// update code called every frame
OpacityTween.prototype.update = function(dt) {
    if (this.app.keyboard.wasPressed(pc.KEY_1)) {
        this.tween.start();
    }
};

Example: https://playcanvas.com/editor/scene/1194337

Press 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants