hilty Posted October 18, 2013 Share Posted October 18, 2013 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, Quote Link to comment Share on other sites More sharing options...
powerfear Posted October 18, 2013 Share Posted October 18, 2013 You can use a tween for that, just tween your object x and y over the duration you want. Quote Link to comment Share on other sites More sharing options...
hilty Posted October 18, 2013 Author Share Posted October 18, 2013 You can use a tween for that, just tween your object x and y over the duration you want. Yep. But what I want is to understand how to implement it. Quote Link to comment Share on other sites More sharing options...
powerfear Posted October 18, 2013 Share Posted October 18, 2013 You can look at some open source javascript tweening library: https://github.com/sole/tween.jshttps://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);} hilty 1 Quote Link to comment Share on other sites More sharing options...
hilty Posted October 19, 2013 Author Share Posted October 19, 2013 You can look at some open source javascript tweening library: https://github.com/sole/tween.jshttps://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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.