Hello can anyone help me with this problem: Im trying to do that this would bounce a image in the canvas area, but i manage to do that only with drawing.
here is my current code that i manage to write, and thanks in advance:
<script type="text/javascript">
var context;
var dx= 4;
var dy=4;
var y=300;
var x=10;
function draw(){
context=canvasArea.getContext('2d');
context.clearRect(0,0,500,500);
context.beginPath();
context.fillStyle="#FF0000";
context.arc(x,y,10,0,Math.PI*2,true);
context.closePath();
context.fill();
if( x<0 || x>500)
dx=-dx;
if( y<0 || y>500)
dy=-dy;
x+=dx;
y+=dy;
}
setInterval(draw,10);
</script>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Vaja 7.3</title>
<style type="text/css">
<!--
body { background-color:#ffffff; font:normal 12px/18px Arial, Helvetica, sans-serif; }
#container { width:600px; }
#canvasArea { background:#fff; border:2px solid #cbcbcb; }
-->
</style>
</head>
<body>
<div id="container">
<canvas id="canvasArea" width="500" height="500"></canvas>
</div>
</body>
</html>