我可以将 javascript 绘图功能更改为图像吗?
Can I change javascript draw function to an image?
我今天在 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 canvas 方法。
http://www.w3schools.com/tags/canvas_fillrect.asp
教程:http://www.html5canvastutorials.com/tutorials/html5-canvas-lines/
我今天在 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 canvas 方法。 http://www.w3schools.com/tags/canvas_fillrect.asp
教程:http://www.html5canvastutorials.com/tutorials/html5-canvas-lines/