如何对画布进行编程以设置 go = true; 当您单击画布上的“播放”一词时,在常规 js 中?如果 go = true,则开始游戏。此代码将 play 打印到画布上。. 这是我的 js 代码:
var canvas = document.getElementById("gameCanvas");
var ctx = canvas.getContext("2d");
canvas.width = 800;
canvas.height = 336;
var go = false;
var reset = function() {
//reset function
};
var main = function () {
//main function
};
var menu = function () {
ctx.clearRect (0 , 0 , canvas.width , canvas.height);
ctx.fillStyle = "rgb(250, 250, 250)";
ctx.font = "24px Helvetica";
ctx.textAlign = "left";
ctx.textBaseline = "middle";
ctx.fillText("play", 32, 32);
}
if (go == true) {
reset();
var then = Date.now();
setInterval(main, 1);
}
else {
menu();
}