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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.