Javascript 如何看到子弹I';我在画布上拍摄?

Javascript 如何看到子弹I';我在画布上拍摄?,javascript,canvas,html5-canvas,javascript-objects,Javascript,Canvas,Html5 Canvas,Javascript Objects,我的画布又有问题了。我目前正在编写一个Javascript空间射击程序 我创建了一个子弹类,希望宇宙飞船能够发射子弹。问题是:没有错误,也没有子弹。我不能完全确定它们是不是没有画出来,或者我就是看不见它们 如果你能帮助我,你真的会帮我很多: 我上传到Git的相关文件(main.js、hold.js): 对不起,德国的评论,但它使我更容易有时:p 我认为问题出在Hold.js中的某个地方: //Kugeln this.leerTaste = false; this.isShooting = fa

我的画布又有问题了。我目前正在编写一个Javascript空间射击程序

我创建了一个子弹类,希望宇宙飞船能够发射子弹。问题是:没有错误,也没有子弹。我不能完全确定它们是不是没有画出来,或者我就是看不见它们

如果你能帮助我,你真的会帮我很多:

我上传到Git的相关文件(main.js、hold.js):

对不起,德国的评论,但它使我更容易有时:p

我认为问题出在Hold.js中的某个地方:

//Kugeln
this.leerTaste = false;
this.isShooting = false;
this.kugeln = [];
this.aktuelleKugel = 0;
//Wenn wir einen neuen Held erstellen, werden 20 Schuss "geladen"
for (var i = 0; i < 20; i++) {
    this.kugeln[this.kugeln.length] = new Kugel();
}
}
//Held Objekt
Held.prototype.draw = function() {
    this.tasteCheck();
    this.held_nase_x = this.held_x + 10;
    this.held_nase_y = this.held_y;
    this.schussCheck();
    this.kugeln_zeichnen();
    ctx.beginPath();
    ctx.fillStyle = this.farbe_ball;
    ctx.arc(this.held_x, this.held_y, this.groese_ball, 0, Math.PI * 2, true);
    ctx.arc(this.held_x - 17, this.held_y, this.groese_ball - 3, 0, Math.PI * 2, true);
    ctx.shadowBlur = this.blur_ball;
    ctx.shadowColor = this.farbe_blur_ball;
    ctx.closePath();
    ctx.fill();
    ctx.shadowColor = "transparent";
};
Held.prototype.tasteCheck = function() {
    if (this.hochTaste == true) {
        this.held_y -= this.speed;
    }
    if (this.rechtsTaste == true) {
        this.held_x += this.speed;
    }
    if (this.linksTaste == true) {
        this.held_x -= this.speed;
    }
    if (this.runterTaste == true) {
        this.held_y += this.speed;
    }
};
//Da unsere Kugeln nur in x-Richtung vom Held aus fliegen, sind sie alle größer als 0.          Der Ursprung findet sich beim Held.
Held.prototype.kugeln_zeichnen = function() {
    for (var i = 0; i < this.kugeln.length; i++) {
        if (this.kugeln[i].held_x >= 0) {
            this.kugeln[i].draw();
        }
    }
}
Held.prototype.schussCheck = function() {
    if (this.leerTaste && !this.isShooting) {
        this.isShooting = true;
        this.kugeln[this.aktuelleKugel].geschossen(this.held_nase_x, this.held_nase_y);
        this.aktuelleKugel++;
        //Wiederverwendne der Kugeln
        if (this.aktuelleKugel >= this.kugeln.length) {
            this.aktuelleKugel = 0;
        }
    } else if (!this.leerTaste) {
        this.isShooting = false;
    }
}
//KUGEL FUNKTIONEN
function Kugel() {
    this.groese_kugel = 3;
    //Kugeln aufbewahren
    this.drawX = -20;
    this.drawY = 0;
}
Kugel.prototype.draw = function() {
    this.drawX += 3;
    ctx.beginPath();
    ctx.fillStyle = '#ff99ff';
    ctx.arc(this.drawX, this.drawY, this.groese_kugel, 0, Math.PI * 2, true);
    ctx.closePath();
    ctx.fill();
    if (this.drawX > width) {
        this.drawX = -20;
    }
};
Kugel.prototype.geschossen = function(startX, startY) {
    //Sagt an was erlaubt ist.
    this.drawX = startX;
    this.drawY = startY;
}
//Kugeln
this.leerTaste=false;
this.isShooting=false;
this.kugeln=[];
此值为0.aktuelleKugel=0;
//我们将在20年前举行一次“geladen”
对于(变量i=0;i<20;i++){
this.kugeln[this.kugeln.length]=new Kugel();
}
}
//持有异议
hold.prototype.draw=函数(){
this.tasteCheck();
this.hold_nase_x=this.hold_x+10;
this.hold\u nase\u y=this.hold\u y;
这个。schuscheck();
这是kugeln_zeichnen();
ctx.beginPath();
ctx.fillStyle=this.farbe_ball;
ctx.arc(this.hold_x,this.hold_y,this.groese_ball,0,Math.PI*2,true);
ctx.arc(this.hold_x-17,this.hold_y,this.groese_ball-3,0,Math.PI*2,true);
ctx.shadowBlur=这个.blur\u球;
ctx.shadowColor=this.farbe\u blur\u ball;
ctx.closePath();
ctx.fill();
ctx.shadowColor=“透明”;
};
hold.prototype.tasteCheck=函数(){
if(this.hochTaste==true){
this.hold_y-=this.speed;
}
if(this.rechtsTaste==true){
this.hold_x+=this.speed;
}
if(this.linkstate==true){
this.hold_x-=this.speed;
}
if(this.runterstaste==true){
this.hold_y+=this.speed;
}
};
//在x-Richtung vom举行的澳大利亚飞行比赛中,这是一场不安全的比赛。这是一个很好的例子。
hold.prototype.kugeln_zeichnen=函数(){
for(var i=0;i=0){
this.kugeln[i].draw();
}
}
}
hold.prototype.schuscheck=函数(){
if(this.leerTaste&&!this.isShooting){
this.isShooting=true;
this.kugeln[this.aktuelleKugel].geschossen(this.hold_nase_x,this.hold_nase_y);
这个.aktuelleKugel++;
//库格伦酒店
如果(this.aktuelleKugel>=this.kugeln.length){
此值为0.aktuelleKugel=0;
}
}否则如果(!this.leerTaste){
this.isShooting=false;
}
}
//KUGEL FUNKTIONEN
函数Kugel(){
this.groese_kugel=3;
//库格伦·奥夫贝瓦伦
这个.drawX=-20;
这个.drawY=0;
}
Kugel.prototype.draw=函数(){
这个.drawX+=3;
ctx.beginPath();
ctx.fillStyle='#ff99ff';
ctx.arc(this.drawX,this.drawY,this.groese_kugel,0,Math.PI*2,true);
ctx.closePath();
ctx.fill();
如果(this.drawX>width){
这个.drawX=-20;
}
};
Kugel.prototype.geschossen=函数(startX,startY){
//萨格特·安是一位伟大的作家。
this.drawX=startX;
this.drawY=startY;
}

顺便问一下,你真的是指
if(laeuft=true){
main.js第46行

if(laeuft=true)
看起来他的意思是
==
。哇,谢谢你!不,它有效了,我现在也看到了我的子弹:)谢谢你指出错误,如果我现在更正了它。显然我有一个缺点,就是编码不好。@user1478242:你绝对应该停止在代码中切换语言。选择德语或英语,否则你会问你自己如果经常“我把这个方法叫做
zeichnen
还是
draw
?这个对象叫做
kugel
还是
bullet
?是的,我想英语肯定是更好的选择。再次感谢您的快速帮助!
Held.prototype.kugeln_zeichnen = function () {
for (var i = 0; i < this.kugeln.length; i++){
    if(this.kugeln[i].held_x >= 0) {
        this.kugeln[i].draw();
       }
   }
}
Held.prototype.kugeln_zeichnen = function () {
    for (var i = 0; i < this.kugeln.length; i++){   
        if(this.kugeln[i].drawX - this.held_nase_x > -20){
            this.kugeln[i].draw();
        }
    }
}