为了账号安全,请及时绑定邮箱和手机立即绑定

为什么海葵还是绘制不出来

//创建一个海葵的类

var aneObj = function(){

this.x =[];//海葵类型定义为一个数组

this.len =[];//海葵的高度

}

aneObj.prototype.num = 50;//海葵数量


//初始化海葵

aneObj.prototype.init = function(){

for(var i =0;i<this.num;i++){

this.x[i] = i * 10 + Math.random()*20;//随机生成海葵的位置

this.len[i] = 200 + Math.random()*50;//随机生成海葵的高度

}

}

//绘制海葵

aneObj.prototype.draw = function(){

for(var i =0;i<this.num;i++){

ctx2.beginPath();//使用beginPath绘制路径

ctx2.moveTo(this.x[i],canHeight);//绘制起始位置

ctx2.lineTo(this.x[i],canHeight - this.len[i]);//绘制结束位置

ctx2.lineWidth=10;

ctx2.lineCap="round";

ctx2.strokeStyle = "purple";//海葵样式,颜色

ctx2.stroke();//先确定样式后执行stroke方法,刷出海葵


}

}


正在回答

1 回答

draw方法放到gameloop函数中了吗?

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
HTML5小游戏---爱心鱼(上)
  • 参与学习       92353    人
  • 解答问题       550    个

学做HTML5游戏,轻轻松松带你上手,适合刚入手游戏开发的同学

进入课程

为什么海葵还是绘制不出来

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信