Jump to content

Move from A to B in X seconds?


hilty
 Share

Recommended Posts

Hi guys,

 

First, I'm sorry if it is a dumb question.

I tryed to ask it to Google but I think that he don't understand my question very well. :)

 

So, I have a object and I need that it go from his current point ( A ) to a new point ( B ) in X miliseconds. How can I do that?

 

Thanks for the answers,

Cheers,

Link to comment
Share on other sites

You can look at some open source javascript tweening library:

 

https://github.com/sole/tween.js

https://github.com/CreateJS/TweenJS/

 

and heres a quick snippet of a very simple interpolation:

var start = {x:0, y:0};var end = {x:200, y:200};var duration = 1000;var frac = 0;var starttime = Date.now();var time = 0;function interpolate(a, b, frac){    var nx = a.x+(b.x-a.x)*frac;    var ny = a.y+(b.y-a.y)*frac;    return {x:nx,  y:ny};}function loop() { //this would be called every frame    time = Date.now();    frac = (time - starttime) / duration;    interpolate(start, end, frac);}
Link to comment
Share on other sites

 

You can look at some open source javascript tweening library:

 

https://github.com/sole/tween.js

https://github.com/CreateJS/TweenJS/

 

and heres a quick snippet of a very simple interpolation:

var start = {x:0, y:0};var end = {x:200, y:200};var duration = 1000;var frac = 0;var starttime = Date.now();var time = 0;function interpolate(a, b, frac){    var nx = a.x+(b.x-a.x)*frac;    var ny = a.y+(b.y-a.y)*frac;    return {x:nx,  y:ny};}function loop() { //this would be called every frame    time = Date.now();    frac = (time - starttime) / duration;    interpolate(start, end, frac);}

 

Hi powerfear,
 
Thanks for your help.
Tween.js solved my problem very well.
And thanks for the piece of code. I don't had any idea how to implement it. :)
 
Cheers.
Link to comment
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...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...