0
我正在尝试使用this“moveTo(x,y)”(通过markE)函数获取多个对象。 This是我试过的。 而这正是我试图做的:在画布中将多个对象移动到x,y坐标
计算和woriking例子是这样的移动物体:
pct += .01;
// if we're not done, request another animation frame
if (pct < 1.00) {
requestAnimFrame(animate);
}
// Calculate the next XY position
var nextX = startingX + dx * pct;
var nextY = startingY + dy * pct;
// Draw the shape
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillRect(nextX, nextY, 40, 30);
而这一点,我尝试了多种形状做:
var shapesLength = shapes.length;
for (var i = 0; i < shapesLength; i++) {// Loop through every object
var tmpShape = shapes[i];//selecting shape
tmpShape.pct += .01;// increment pct towards 100%
// if we're not done, request another animation frame
if (tmpShape.pct < 1.00) {
requestAnimFrame(animate);
}
// Calculate the next XY position
var nextX = tmpShape.startingX + tmpShape.dx * tmpShape.pct;
var nextY = tmpShape.startingY + tmpShape.dy * tmpShape.pct;
// Draw the shape
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillRect(nextX, nextY, 10, 10);
};
但是出了点问题,我不知道是什么。
下面是如何实现每个形状的多个路点的例子:http://jsfiddle.net/m1erickson/UNjdC/ – markE
如何创建对象的即时生成并在到达目标点后对其进行清理? – eko24
shapes []数组包含将绘制和动画的所有形状的定义。在这种情况下,形状都是具有开始/结束动画点和颜色的矩形。如果您想要立即生成对象,只需将新对象添加到shapes []数组。如果您希望对象在到达目标点后消失,请删除以下行:drawShape(shape,shape.waypoints.length - 1); – markE