// 定义海葵对象类
var aneObj = function()
{
this.x = []; //海葵x位置
this.len = []; //海葵长度
}
// 定义海葵原型对象数量
aneObj.prototype.num = 50;
// 海葵初始化,随机产生海葵x位置和长度
aneObj.prototype.init = function()
{
for (var i = 0; i < this.num; i++)
{
this.x[i] = i *16 + Math.random() *20; //[0,1)
this.len[i] = 200 + Math.random() *50;
//console.log("a");
}
}
// 画海葵
aneObj.prototype.draw = function()
{
ctx2.save();
ctx2.globalAlpha = 0.6;//海葵的透明度
ctx2.lineCap = "round";//海葵线头形状
ctx2.strokeStyle = "#3b154a";//海葵的颜色
ctx2.lineWidth = 20; //海葵的粗细
for(var i = 0; i<this.num; i++)
{
//beginPath, moveTo, lineTo, lineWidth, lineCap, strokeStyle, stroke
ctx2.beginPath();
ctx2.moveTo(this.x[i], canHeight);
ctx2.lineTo(this.x[i], canHeight - this.len[i]);
ctx2.stroke();
}
ctx2.restore();
}
大鱼吃小鱼游戏-ane.js
最新推荐文章于 2016-05-16 20:27:46 发布