Hello could somebody tell me wath is wrong with my code. When i do the clear rect, it’s doesn’t work.
I just try to move the ball in the canvas. Actually my ball leave a mark. This kind of line is leave.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="_js/jquery1.6.js" type="text/jscript"></script>
</head>
<body>
<canvas id="dropBall" width="400" height="400"></canvas>
<script>
var dropBall = $("#dropBall")[0];
var dropContext = dropBall.getContext("2d");
dropContext.fillStyle = "green";
var ballX = 200;
var ballY = 200;
function activeBall() {
dropContext.clearRect(0, 0, dropBall.width, dropBall.height);
dropContext.arc(ballX, ballY, 10, 2 * Math.PI, 0, true);
dropContext.fill();
ballY--;
ballX++;
var time = 100;
setTimeout("activeBall()", time);
}
activeBall();
</script>
</body>
Shouldn’t it be:
or am I misunderstanding something?
If you do it the other way around, then the only rectangle getting cleared is the square from (0,0) to (width of ball,height of ball).
EDIT:
It actually might be
If your ball is centered at ballX.
EDIT EDIT:
I fixed it for you:
The specific lines are: