首页 > 解决方案 > 画布复制多个形状

问题描述

我想将 10 添加到球的位置,但它会为复制的形状添加位置。我试图制作一个单独的功能,但它不起作用。

HTML5 代码:

 <!DOCTYPE html>
 <html>
 <head>
 <meta charset="utf-8">
 <title></title>
 </head>
 <body>
 <canvas id="Game" width="800" height="600" style="border: 1px solid #d3d3d3;
 background-color: #f1f1f1;"></canvas>
 <script src="Game.js"></script>
 </body>
 </html>

 Javascript Code:

  var GameCanvas = GameCanvas = document.getElementById("Game");
  var GameCtx = GameCtx = GameCanvas.getContext("2d");;
  var BallSprite = 50;

  window.onload = function () {

  setInterval(HoldSprites, 100);
  }

  function HoldSprites() {
  BallSprite = BallSprite + 10;
    GameCtx.beginPath();
    GameCtx.arc(BallSprite, 50, 40, 0, 2 * Math.PI);
    GameCtx.stroke();
    }

标签: javascripthtml5-canvas

解决方案


推荐阅读