<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
#map{border: 2px solid black}
</style>
<script>
window.onload = function(){
var canvas = document.getElementById("map"),
c = canvas.getContext("2d");
c.fillStyle = "white";
c.fillRect(0, 0, canvas.width, canvas.height);
/*aisles*/
c.fillStyle = "#009900";
c.fillRect (20,90,20,250);
c.fillRect (70,90,20,250);
c.fillRect (120,90,20,250);
c.fillRect (170,90,20,250);
c.fillRect (220,90,20,250);
c.fillRect (270,90,20,250);
c.fillRect (470,90,20,250);
c.fillRect (520,90,20,250);
c.fillRect (570,90,20,250);
c.fillRect (620,90,20,250);
c.fillRect (670,90,20,250);
c.fillRect (720,90,20,250);
c.fillRect (770,90,20,250);
c.fillStyle = "#0066cc";
c.fillRect (320,90,20,250);
c.fillRect (370,90,20,250);
c.fillRect (420,90,20,250);
/*sections*/
c.fillStyle = "#009900";
c.fillRect (700, 400,200,50);
c.fillRect (850,0,50,300);
c.fillRect (850, 365, 50, 85);
c.fillRect (175,0,555,50);
c.fillRect (0,0,150,50);
/*section names*/
c.fillStyle = "white";
c.font = "25px Arial";
c.fillText("Dairy" ,45,30);
c.fillText("-----Meat------", 375, 30);
c.fillText("Produce",750, 435);
c.fillText("B", 865, 90);
c.fillText("a", 865, 115);
c.fillText("k", 865, 140);
c.fillText("e", 865, 165);
c.fillText("r", 865, 190);
c.fillText("y", 865,215);
/*aisle numbers*/
c.fillStyle = "white";
c.font = "12px Arial";
c.fillText("16", 22, 210);
c.fillText("15", 72, 210);
c.fillText("14", 122, 210);
c.fillText("13", 172, 210);
c.fillText("12", 222, 210);
c.fillText("11", 272, 210);
c.fillText("10", 322, 210);
c.fillText("9", 376, 210);
c.fillText("8", 426, 210);
c.fillText("7", 476, 210);
c.fillText("6", 526, 210);
c.fillText("5", 576, 210);
c.fillText("4", 626, 210);
c.fillText("3", 676, 210);
c.fillText("2", 726, 210);
c.fillText("1", 776, 210);
c.beginPath();
c.fillStyle = "#009900";
c.arc(550,450,50,0,2,true);
c.fill();
c.beginPath();
c.fillStyle = "#009900";
c.arc(200,450,50,0,2,true);
c.fill();
/*animation sequence*/
var posX = 550;
var posY = 450;
setInterval(function(){
posX += 1;
if(posX >= 540){
posY += -1;
}
c.fillStyle = "red";
c.beginPath();
c.arc(posX,posY, 5, 0, Math.PI*2, false);
c.fill();
},30);
};
</script>
<title>Canvas Map</title>
</head>
<body>
<canvas id="map" width="900" height="450">
<img src="images/sad dinosaur.jpg" />
You will need an updated browser to view this page!
(Chrome,Firefox, etc...)
</canvas>
</body>
</html>
我想制作一个动画,红色圆圈会在没有绘制在他们身上的过道(像迷宫)上下走动。我一直试图使用if/else语句来强制执行动画的方向。但是,当我尝试使用第二个if语句来更改圆形过程时,它会在该坐标点处开始我的圆形。HTML画布if/else
你能发表一个问题的例子吗?目前我看到一个向左斜向移动的球。你试图做什么,当你做了什么? – 2014-10-08 19:12:29