我想使用JavaScript的畫布做傍。如何清除畫布中圓圈的前一個位置?
我做了任何遊戲已經很多年了,因此我相當初學。
我有一個問題,我試圖移動球(只是它的X位置,現在),並試圖刪除其以前的位置。我使用的代碼爲槳(向上和向下鍵移動它)工作。
但是,它似乎並不想與球一起工作。
我在做什麼錯?
this.draw = function() {
ctx.clearRect(this.prevX - this.radius, this.prevY - this.radius, this.radius * 2, this.radius * 2);
ctx.fillStyle = this.color;
ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2, true);
ctx.fill();
this.prevX = this.x;
this.prevY = this.y;
}
我知道我使用的是clearRect()
,但我的印象只是刪除了畫布的矩形部分。
clearRect(x,y,width,height)
:清除指定區域,並使其完全透明
隨意給我任何其他提示,因爲我幾乎是一個初學者與此。
我知道我錯過了一些東西!非常感謝! :) – alex 2011-04-27 23:20:07