简体   繁体   English

Javascript错误:第一行的输入意外结束,没有任何明显的问题,但是我收到一条消息,整个画布停止了

[英]Javascript error: I have a unexpected end of input on my first line, with no apparent problems, but I'm getting a message and the whole canvas stops

I put in the entire thing just in case I went into chrome and looked for errors, and it wasnt working either so I checked, apparently the first line has a problem. 我把整个东西放进去,以防万一我进入chrome并查找错误,但是它也不起作用,所以我检查了一下,显然第一行出现了问题。 I kept the first 6 lines and deleted all else then it worked fine, so I went to SublimeText2 and searched for every ) and } in the code. 我保留了前6行并删除了所有其他行,然后一切正常,因此我转到SublimeText2并在代码中搜索了每个)和}。

var canvasBg = document.getElementById('canvasBg');
var ctxBg = canvasBg.getContext('2d');


var canvasJet = document.getElementById('canvasJet');
var ctxJet = canvasJet.getContext('2d');

var jet1;
var fps = 17;
var drawInterval;

var imgSprite = new Image();
imgSprite.src = 'SpriteSheet.png'
imgSprite.addEventListener('load',init,false);


function init() {
    drawBg();
    startDrawing();
    jet1 = new Jet();
    document.addEventListener('keydown',checkKeyDown,false);
    document.addEventListener('keyup',checKeyUp,false);
}

function draw() {
    jet1.draw();
}


function startDrawing() {
    stopDrawing();
    drawInterval = setInterval(draw,fps);
}


function stopDrawing() {
    clearInterval(setInterval);
}



Jet.prototype.draw = function() {
    clearCtxJet();
    ctxJet.drawImage(imgSprite,this.srcX,this.srcY,this.width,this.height,this.drawX,this.drawY,this.width,this.height);

};




function Jet() {
    this.srcX = 0;
    this.srcY = 0;
    this.drawX = 200;
    this.drawY = 200;
    this.width = 96;
    this.height = 30;
    }



function drawJet() {
}





function drawBg() {

    ctxBg.drawImage(imgSprite,96,0,800,500,0,0,800,500)

}

function clearCtxBg() {
    ctxBg.clearRect(0,0,800,500);
}

function clearCtxJet() {
    ctxJet.clearRect(0,0,800,500);
}



function checkKeyDown(e) {

    var keyID = (e.keyCode) ? e.keyCode : e.which;
    if (keyID === 38) { // 38 is up key
        alert('up arrow was pressed');
        e.preventDeafault();
    }

    if (keyID === 39) { // 39 is right key
        e.preventDeafault();
    }

    if (keyID === 40) { // 40 is down key
        e.preventDeafault();
    }

    if (keyID === 37) { // 37 is left key
        e.preventDeafault();
    }


function checkKeyup(e) {

    var keyID = (e.keyCode) ? e.keyCode : e.which;
    if (keyID === 38) { // 38 is up key
        alert('up arrow was pressed');
        e.preventDeafault();
    }

    if (keyID === 39) { // 39 is right key
        e.preventDeafault();
    }

    if (keyID === 40) { // 40 is down key
        e.preventDeafault();
    }

    if (keyID === 37) { // 37 is left key
        e.preventDeafault();
    }

} }

I assume you're showing only parts of the code so there's no way of knowing whether this is the actual error, but both checkKeyup and checkKeydown are missing closing braces. 我假设您只显示代码的一部分,所以无法知道这是否是实际错误,但是checkKeyup和checkKeydown都缺少右括号。

I recommend installing Package Control for Sublime Text 2 and then using it to install SublimeLinter which will be able to check your code for you and point out missing semicolons and braces. 我建议为Sublime Text 2安装Package Control ,然后使用它来安装SublimeLinter ,它将能够为您检查代码并指出缺少的分号和花括号。

看到http://jsfiddle.net的完整代码将非常高兴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的 discord 机器人出现“SyntaxError: Unexpected end of input” - I'm getting a “SyntaxError: Unexpected end of input” on my discord bot 我在我的节点 js 代码中收到错误意外的输入结束 - i am getting error unexpected end of input in my node js code Javascript:我收到错误“Uncaught SyntaxError:Unexpected token {” - Javascript: I'm getting the error “Uncaught SyntaxError: Unexpected token { ” 我的Javascript脚本中出现意外的字符串错误 - I have an Unexpected String error in my Javascript Script JavaScript .js文件的第1行中输入错误的意外结束 - Unexpected end of input error in line 1 of JavaScript .js file JavaScript 错误:输入意外结束 - JavaScript Error : Unexpected end of input JavaScript意外结束输入错误 - Unexpected End of Input Error on javascript Javascript使数组的数组变平但是我的for循环出现错误? - Javascript flattening an array of arrays but I'm getting error in my for loop? I have some problems related to Javascript and HTML5 Canvas element and PHP CURL within my game - I have some problems related to Javascript and HTML5 Canvas element and PHP CURL within my game 当我使用 message.htmlView 在 adonis js 中发送邮件时出现错误 - I have getting error when i'm using message.htmlView to send mail in adonis js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM