图像不会出现在JavaScript编码中

时间:2017-08-17 01:17:42

标签: javascript

这段代码的结果应该显示一个浮动的图像但是我搞砸了某个地方并且我的文本编辑器上的错误系统(将红色X放在边缘的那个,我忘了它被称为的那个)被禁用了我似乎无法找到如何打开它。



// CONSTANTS
var CANVAS_WIDTH = 800;
var NANONAUT_WIDTH = 118;
var nanonautX = CANVAS_WIDTH - NANONAUT_WIDTH;
var CANVAS_HEIGHT = 600;
var NANONAUT_HEIGHT = 229;
var GROUND_Y = 540;
// SETUP
var canvas = document.createElement("canvas");
var c = canvas.getContext("2d");
canvas.width = CANVAS_WIDTH;
canvas.height = CANVAS_HEIGHT;
document.body.appendChild(canvas);

var nanonautImage = new Image();
nanonautImage.src = "dad.png";

var nanonautX = 50;
var nanonautY = 40;

window.addEventListener("load", start);

function start() {
  window.requestAnimationFrame(mainLoop);
}
// MAIN LOOP
function mainLoop() {
  update();
  draw();
  window.requestAnimationFrame(mainLoop);
}
// PLAYER INPUT
// UPDATING
function update() {
  
}
// DRAWING
function draw() {
  c.clearRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT);
  
  c.drawImage(nanonautImage, nanonautX, nanonautY);
}




0 个答案:

没有答案