HTML5 Canvas简单淡入淡出游戏启动界面

欢迎访问博主的网站:[url]http://www.108js.com[/url]
查看效果:[url]http://www.108js.com/article/article3/game/ex1/exam.html[/url]

效果图:
[img]http://dl2.iteye.com/upload/attachment/0097/8010/ee30220a-6775-31c9-b338-707bae41dc57.gif[/img]

一、HTML代码:
<!DOCTYPE html>
<html lang='zh'>
<head>
<meta charset='gbk' />
<title>HTML5 Canvas 简单淡入淡出__www.108js.com</title>
<script src='introState.js'></script>
</head>
<body>
<canvas id='canvas' width='700' height='500'> 你的浏览器不支持canvas</canvas>
</body></html>
<script>
var requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback){
window.setTimeout(callback, 1000 / 60);
};
})();

window.cancelRequestAnimFrame = ( function() {
return window.cancelAnimationFrame ||
window.webkitCancelRequestAnimationFrame ||
window.mozCancelRequestAnimationFrame ||
window.oCancelRequestAnimationFrame ||
window.msCancelRequestAnimationFrame ||
clearTimeout
} )();

var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var intro;
var w=canvas.width;
var h=canvas.height;
var timer;
document.onkeydown = function(event){
var code = event.keyCode || event.which;
if(code==13){
cancelRequestAnimFrame(timer);
gameStart();
}

}


function init() {
intro=new introState();
animation();
}

function animation(){
intro.update();//更新
intro.draw(ctx,w,h);//绘制
timer=requestAnimFrame(animation);
};


function gameStart() {
alert("游戏开始");
paintCanvas();
}


function paintCanvas() {
ctx.fillStyle = "black";
ctx.fillRect(0, 0, w, h);
}

init();
</script>

二、introState.js
代码就不贴了,请下载。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值