我可以将javascript绘制函数更改为图像吗

Can I change javascript draw function to an image?

本文关键字:图像 函数 javascript 绘制 我可以      更新时间:2023-09-26

我在github上找到了一个游戏代码[https://github.com/maryrosecook/retro-games]今天。我想编辑它,并使用png图像而不是绘图功能,有什么我可以做到的吗?非常感谢。

  BodyBlock.prototype = {
    draw: function(screen) {
      drawRect(screen, this, "black");
    }

drawRect()是自定义的、从头开始的函数。

var drawRect = function(screen, body, color) {
  screen.fillStyle = color;
  screen.fillRect();
};

您正在寻找的是标准的javascript画布方法。http://www.w3schools.com/tags/canvas_fillrect.asp

教程:http://www.html5canvastutorials.com/tutorials/html5-canvas-lines/