我有以下代码应该是动画的三帧,如何将它们变成 Kinetic.js 中的动画?这是一个像吃豆人一样的六角形,可以打开和关闭它的嘴。我有三个画布图像,作为三个框架,Kinetic.js 中是否有任何内置函数可以做到这一点?还是我应该从头开始创建一个?在我制作了精灵之后,我怎样才能在不破坏动画的情况下进行其他动画,比如移动它或旋转它(吃豆人应该仍然张开和关闭它的嘴)?
pacMan1 = new Kinetic.Shape({
x: 15,
y: 13,
//fill: 'rgb(62, 53, 67)',
// a Kinetic.Canvas renderer is passed into the drawFunc function
drawFunc: function (canvas) {
var context = canvas.getContext();
// layer1/Compound Path
context.save();
context.beginPath();
// layer1/Compound Path/Path
context.moveTo(54.0, 12.8);
context.lineTo(34.2, 1.4);
context.bezierCurveTo(31.2, -0.3, 27.6, -0.3, 24.7, 1.4);
context.lineTo(4.9, 12.8);
context.bezierCurveTo(1.9, 14.5, 0.1, 17.7, 0.1, 21.0);
context.lineTo(0.1, 43.9);
context.bezierCurveTo(0.1, 47.3, 1.9, 50.5, 4.9, 52.1);
context.lineTo(24.7, 63.6);
context.bezierCurveTo(27.6, 65.3, 31.2, 65.3, 34.2, 63.6);
context.lineTo(54.0, 52.1);
context.bezierCurveTo(56.9, 50.5, 58.7, 47.3, 58.7, 43.9);
context.lineTo(58.7, 21.0);
context.bezierCurveTo(58.7, 17.7, 56.9, 14.5, 54.0, 12.8);
context.closePath();
// layer1/Compound Path/Path
context.moveTo(32.3, 10.8);
context.bezierCurveTo(30.7, 10.8, 29.5, 9.5, 29.5, 8.0);
context.bezierCurveTo(29.5, 6.4, 30.7, 5.1, 32.3, 5.1);
context.bezierCurveTo(33.9, 5.1, 35.1, 6.4, 35.1, 8.0);
context.bezierCurveTo(35.1, 9.5, 33.9, 10.8, 32.3, 10.8);
context.closePath();
context.fillStyle = "rgb(62, 53, 67)";
context.fill();
context.lineWidth = 0.3;
context.stroke();
canvas.fillStroke(this);
context.restore();
}
});
pacMan2 = new Kinetic.Shape({
x: 15,
y: 13,
//fill: 'rgb(62, 53, 67)',
// a Kinetic.Canvas renderer is passed into the drawFunc function
drawFunc: function (canvas) {
var context = canvas.getContext();
// layer1/Compound Path
context.save();
context.beginPath();
// layer1/Compound Path/Path
context.moveTo(29.1, 36.9);
context.bezierCurveTo(27.6, 36.0, 26.7, 34.5, 26.7, 32.8);
context.bezierCurveTo(26.7, 31.2, 27.6, 29.6, 29.1, 28.8);
context.lineTo(55.2, 13.7);
context.bezierCurveTo(54.8, 13.4, 54.4, 13.1, 54.0, 12.8);
context.lineTo(34.2, 1.4);
context.bezierCurveTo(31.2, -0.3, 27.6, -0.3, 24.7, 1.4);
context.lineTo(4.9, 12.8);
context.bezierCurveTo(1.9, 14.5, 0.1, 17.7, 0.1, 21.0);
context.lineTo(0.1, 43.9);
context.bezierCurveTo(0.1, 47.3, 1.9, 50.5, 4.9, 52.1);
context.lineTo(24.7, 63.6);
context.bezierCurveTo(27.6, 65.3, 31.2, 65.3, 34.2, 63.6);
context.lineTo(54.0, 52.1);
context.bezierCurveTo(54.2, 52.0, 54.5, 51.8, 54.7, 51.7);
context.lineTo(29.1, 36.9);
context.closePath();
// layer1/Compound Path/Path
context.moveTo(32.3, 5.1);
context.bezierCurveTo(33.9, 5.1, 35.1, 6.4, 35.1, 8.0);
context.bezierCurveTo(35.1, 9.5, 33.9, 10.8, 32.3, 10.8);
context.bezierCurveTo(30.7, 10.8, 29.5, 9.5, 29.5, 8.0);
context.bezierCurveTo(29.5, 6.4, 30.7, 5.1, 32.3, 5.1);
context.closePath();
context.fillStyle = "rgb(62, 53, 67)";
context.fill();
context.lineWidth = 0.3;
context.stroke();
canvas.fillStroke(this);
context.restore();
}
});
pacMan3 = new Kinetic.Shape({
x: 15,
y: 13,
//fill: 'rgb(62, 53, 67)',
// a Kinetic.Canvas renderer is passed into the drawFunc function
drawFunc: function (canvas) {
var context = canvas.getContext();
// layer1/Compound Path
context.save();
context.beginPath();
// layer1/Compound Path/Path
context.moveTo(32.0, 36.9);
context.bezierCurveTo(28.7, 36.0, 26.7, 34.5, 26.7, 32.8);
context.bezierCurveTo(26.7, 31.2, 28.7, 29.6, 32.0, 28.8);
context.lineTo(58.7, 22.0);
context.lineTo(58.7, 21.0);
context.bezierCurveTo(58.7, 17.7, 56.9, 14.5, 54.0, 12.8);
context.lineTo(34.2, 1.4);
context.bezierCurveTo(31.2, -0.3, 27.6, -0.3, 24.7, 1.4);
context.lineTo(4.9, 12.8);
context.bezierCurveTo(1.9, 14.5, 0.1, 17.7, 0.1, 21.0);
context.lineTo(0.1, 43.9);
context.bezierCurveTo(0.1, 47.3, 1.9, 50.5, 4.9, 52.1);
context.lineTo(24.7, 63.6);
context.bezierCurveTo(27.6, 65.3, 31.2, 65.3, 34.2, 63.6);
context.lineTo(54.0, 52.1);
context.bezierCurveTo(56.9, 50.5, 58.7, 47.3, 58.7, 43.9);
context.lineTo(58.7, 43.7);
context.lineTo(32.0, 36.9);
context.closePath();
// layer1/Compound Path/Path
context.moveTo(32.3, 5.1);
context.bezierCurveTo(33.9, 5.1, 35.1, 6.4, 35.1, 8.0);
context.bezierCurveTo(35.1, 9.5, 33.9, 10.8, 32.3, 10.8);
context.bezierCurveTo(30.7, 10.8, 29.5, 9.5, 29.5, 8.0);
context.bezierCurveTo(29.5, 6.4, 30.7, 5.1, 32.3, 5.1);
context.closePath();
context.fillStyle = "rgb(62, 53, 67)";
context.fill();
context.lineWidth = 0.3;
context.stroke();
canvas.fillStroke(this);
context.restore();
}
});