Sign in to follow this  
trial

How to move a button after tweening it's alpha?

Recommended Posts

Hi, I manage to figure out how to tween a button's alpha from 1 to 0.5, using tweenjs. Now I can't seem to get it to jump to a certain location after the alpha is 0.5:

this.coverBtn.addEventListener("click", coverBtnfadeOutClick.bind(this));

function coverBtnfadeOutClick() {
	createjs.Tween.get(this.coverBtn)
		.to({
			alpha: 0.5
		}, 100, createjs.Ease.none);
	if (this.coverBtn.alpha == 0.5) {
		this.coverBtn.x += 100;
	}
}

I usually just use onEnterFrame for AS2 in Flash era. How do I do that for html5?

Share this post


Link to post
Share on other sites

Looks like your if statement isn't waiting until your tween has completed. So, the script calls tween, then immediately calls the if statement without pausing to wait until the tween has completed.. thus this.coverBtn.alpha is not equal to 0.5 so the coordinate shift doesn't happen. You need a callback or in this case 'onComplete' event.

Example of onComplete event binding here: https://www.createjs.com/docs/tweenjs/modules/TweenJS.html

Cheers!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.