From 5f1157664d13e2422f5c7ff2fe72f56d33fd8880 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E6=B5=A9=E4=B9=90?= Date: Fri, 1 Jan 2016 08:00:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=9B=B4=E6=96=B0=E5=92=8C?= =?UTF-8?q?=E7=BB=98=E5=88=B6=E5=88=86=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- game.js | 8 +++++--- index.js | 8 ++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/game.js b/game.js index d8e3dea..21d4560 100644 --- a/game.js +++ b/game.js @@ -36,7 +36,8 @@ function Game(id,options){ y:0 }, speed:1, //速度等级,内部计算器times多少帧变化一次 - update:function(){} //更新参数信息 + update:function(){}, //更新参数信息 + draw:function(){} //绘制 }; for(var i in settings){ this[i] = options[i]||settings[i]; @@ -89,9 +90,10 @@ function Game(id,options){ f++; stage.items.forEach(function(item,index){ if(!(f%item.speed)){ - item.times = f/item.speed; //计数器 + item.frames = f/item.speed; //计数器 } - item.update(_context); + item.update(); + item.draw(_context); }); _hander = requestAnimationFrame(fn); } diff --git a/index.js b/index.js index aa1333f..d6bfd65 100644 --- a/index.js +++ b/index.js @@ -19,10 +19,10 @@ width:100, height:100, speed:10, - update:function(context){ + draw:function(context){ context.fillStyle = '#FC3'; context.beginPath(); - if(this.times%2){ + if(this.frames%2){ context.arc(this.x,this.y,this.width/2,.20*Math.PI,1.80*Math.PI,false); }else{ context.arc(this.x,this.y,this.width/2,.01*Math.PI,1.99*Math.PI,false); @@ -41,7 +41,7 @@ stage.createItem({ x:game.width/2, y:game.height*.6, - update:function(context){ + draw:function(context){ context.font = 'bold 42px Helvetica'; context.textAlign = 'center'; context.textBaseline = 'middle'; @@ -53,7 +53,7 @@ stage.createItem({ x:game.width-12, y:game.height-5, - update:function(context){ + draw:function(context){ context.font = '14px Helvetica'; context.textAlign = 'right'; context.textBaseline = 'bottom';