关于canvas动画怎么让里面的图片动起来?


<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8" />

<title></title>

<script src="js/jquery-1.9.1.min.js"></script>

<style>

body{margin: 0; padding: 0;}

</style>

</head>

<body>

<canvas id="canvas"></canvas>

</body>

<script type="text/javascript">

var w=$(window).width();

var h=$(window).height();

var c=document.getElementById("canvas");

c.width=w;

c.height=h-60;

var ctx=c.getContext("2d");

var img=new Image();

var img1=new Image();

var hua=new Image();

img.src="img/yueliang.png";

img1.src="img/s1.png"

hua.src="img/hua3.png"

img.onload=function(){

ctx.drawImage(img,0,0,w,w/2.05)

ctx.drawImage(img1,0,200,w,w/1.25)

so(0,900)

}

function so(x,y){

ctx.drawImage(hua,x,y)


}

var x=0,y=0

setInterval(function(){

x+=5;

y+=5;

},100)





</script>

</html>



sdwsq
浏览 4589回答 1
1回答

小白师兄

在你的定时器里面调用你的so(x,y)方法!  像这个样子setInterval(function() {     x += 5;     y += 5;     so( x, y)      }, 100)
打开App,查看更多内容
随时随地看视频慕课网APP