キャンバス上に2つの点(x/y)があり、requestanimationframeまたはsetintervalを使用して直線の間で画像を移動できます。JS - 2Dベクトルをカーブに変換する
:?!しかし、代わりに私は、このJSBinを作成して、何とか、したいと曲がったアニメーションでオブジェクトを移動、速度X/Y、特にS(ステップ)のベクトルの組み合わせによって う
http://jsbin.com/furomu/edit?html,js,console,output - (クリックしてください)。
この「ベクトル」をなんらかの形でカーブにして滑らかな動きを描くことは可能ですか? もしそうでなければ、私はそれを曲がった動きに変えるのに何か他の値を必要としますか?
//start at 50,50
//move to 150,125
// Vector is 100/75 or v +1/+0.75 at 100 steps
function Move(ox, oy, x, y){
this.ox = ox;
this.oy = oy;
this.x = x
this.y = y
this.p;
this.v = {x: x - ox, y: y - oy};
this.setup = function(){
var p = {};
var v = this.v;
if (this.x > this.y){
p.s = v.y;
p.y = 1;
p.x = v.x/v.y;
}
else {
p.s = v.x;
p.x = 1;
p.y = v.y/v.x;
}
this.p = p;
}
this.setup();
}
function Ship(x, y){
this.x = x;
this.y = y;
this.moves = [];
this.draw = function(){
this.drawSelf();
this.drawTarget();
}
this.create = function(){
var move = new Move(this.x, this.y, 150, 125);
this.moves.push(move);
}
this.update = function(){
var m = this.moves[0];
var self = this;
anim = setInterval(function(){
ctx.clearRect(0, 0, res, res);
self.x += m.p.x;
self.y += m.p.y;
m.p.s--;
self.draw();
if (m.p.s == 0){
clearInterval(anim);
}
}, 30);
}
this.create();
this.draw();
this.update();
}
function init(){
var ship = new Ship(50, 50);
}
曲線を定義するには3点以上が必要です。 Googleのスプライン。ベロシティを持っている場合は、スタートポイントから最初のベロシティ方向に前方に突き出して3番目のポイントを定義することができます。 – samgak