提交 5ca200e8 编写于 作者: X xty

修复canvas iOS运行报错

上级 c3310982
...@@ -85,23 +85,23 @@ ...@@ -85,23 +85,23 @@
let canvasWidth = this.ctx.canvas.width, let canvasWidth = this.ctx.canvas.width,
canvasHeight = this.ctx.canvas.height canvasHeight = this.ctx.canvas.height
for (let i = 0; i < this.layer; i++) { for (let i = 0; i < this.layer; i++) {
let radius = getDistance(canvasWidth / 2, canvasHeight / 2) / layer * i let radius = this.getDistance(canvasWidth / 2, canvasHeight / 2) / this.layer * i
for (let j = 0; j < this.ballInlayer; j++) { for (let j = 0; j < this.ballInlayer; j++) {
let deg = j * 2 * Math.PI / ballInlayer, let deg = j * 2 * Math.PI / this.ballInlayer,
sin = Math.sin(deg), sin = Math.sin(deg),
cos = Math.cos(deg), cos = Math.cos(deg),
x = radius * cos + canvasWidth / 2, x = radius * cos + canvasWidth / 2,
y = radius * sin + canvasHeight / 2, y = radius * sin + canvasHeight / 2,
vx = this.speed * cos, vx = this.speed * cos,
vy = this.speed * sin vy = this.speed * sin
ballList.push(new Ball(x, y, vx, vy, ctx, devicePixelRatio)) this.ballList.push(new Ball(x, y, vx, vy, this.ctx, devicePixelRatio))
} }
} }
} }
private animate(ballList: Array<Ball>) { private animate(ballList: Array<Ball>) {
this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height ) this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height )
ballList.forEach(function(item) { this.ballList.forEach(function(item) {
item.move() item.move()
item.draw() item.draw()
}) })
...@@ -111,8 +111,8 @@ ...@@ -111,8 +111,8 @@
start(){ start(){
//Todo.. requestAnimationFrame //Todo.. requestAnimationFrame
clearInterval(this.interval) clearInterval(this.interval)
interval = setInterval(function() { this.interval = setInterval(()=> {
animate(ballList) this.animate(this.ballList)
}, 17) }, 17)
} }
stop(){ stop(){
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册