html5怎么设置逐帧动画,HTML5 - 逐帧动画不起作用

我有这个帧动画,其中每个帧在每1/30s被调用。HTML5 - 逐帧动画不起作用

画布根本没有被正确清除。为什么?

下面是代码:

var canvas;

var stage;

var screen_width;

var screen_height;

var bmpAnimation;

// this is a list of keyframes for each image parameter to be animated

var beachX = new Array(102,130,140,200, 233, 211, 133, 455,222);

var beachY = new Array(52,120,240,400, 102,130,140,200, 233);

var beachRotation = new Array(102,30,140,200, 33, 211, 133, 355,222);

var beachOpacity = new Array(0, 0.5, 1, 0.3, 0.8, 0.3, 0.9, 0.3, 1);

var beachScaleX = new Array(0, 0.5, 0.7, 0.3, 0.8, 1, 0.9, 0.2, 1);

var beachScaleY = new Array(0.3, 0, 0.5, 0.7, 0.3, 0.8, 1, 0.9, 1);

var index = 0;

var beach;

var context;

var interval;

window.onload = init;

function make_beach()

{

beach = new Image();

beach.src = "beach.png"; // this can be any image that is large (at least 600 x 600 pixels)

beach.onload = function(){

context.drawImage(beach, 70,120);

}

}

function init() {

canvas = document.getElementById("myCanvas");

context = canvas.getContext('2d');

context.save();

make_beach();

interval = setInterval("tick()",33);

stage = new Stage(canvas);

}

function degreesToRadians(num) {

return num * 0.0174532925199432957;

}

function tick() {

var numberOfFrames = beachX.length;

if (index > (numberOfFrames -1)) {

clearInterval (interval); // cancel the timer

return;

}

context.restore();

context.globalAlpha = 1;

context.clearRect(0, 0, canvas.width, canvas.height);

var beachMiddleX = beach.width * 0.5;

var beachMiddleY = beach.height * 0.5;

context.translate(beachX[index] + beachMiddleX, beachY[index] + beachMiddleY);

context.scale(beachScaleX[index], beachScaleY[index]);

context.rotate(degreesToRadians(beachRotation[index]));

context.globalAlpha = beachOpacity[index];

context.translate(-beachMiddleX, -beachMiddleY);

context.drawImage(beach, beachX[index], beachY[index]);

context.restore();

index ++;

}

Your browser doesn't support canvas. Please download a modern browser

2012-07-14

SpaceDog

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值