Skip to main content
Known Participant
May 18, 2019
Answered

Easing with JS

  • May 18, 2019
  • 2 replies
  • 1048 views

Hello,

I need something simple, hope someone got a clue how to do it:

for example the code is placed in specific frame in HTML5 canvas project:    this.Object.x = this.Object.x + 200

how can I make the change of Object.x to happen with easing.

Thanks!

This topic has been closed for replies.
Correct answer kglad

the easiest to use is

speed = .5;  // closer to zero, the slower the ease.  closer to 1, faster the ease.

this.Object.x = (1-speed)*this.Object.x+speed*endX;  // endX for you might be 200.

2 replies

Legend
May 18, 2019

Just use the built-in tween library.

cjs.Tween.get(this.Object).to({x: this.Object.x + 200}, 1000, cjs.Ease.cubicOut);

https://www.createjs.com/docs/tweenjs/modules/TweenJS.html

https://www.createjs.com/docs/tweenjs/classes/Ease.html

kglad
Community Expert
Community Expert
May 18, 2019
vatza_aAuthor
Known Participant
May 18, 2019

Thanks a lot - it looks like it is what I need but I will need a new diploma and 7 years to understand it. If you can help me out a bit

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
May 18, 2019

the easiest to use is

speed = .5;  // closer to zero, the slower the ease.  closer to 1, faster the ease.

this.Object.x = (1-speed)*this.Object.x+speed*endX;  // endX for you might be 200.