Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to see the Bullets I'm shooting on Canvas?
    primarykey
    data
    text
    <p>Again im having a Problem with my Canvas. I'm currently programming a Javascript Space Shooter. </p> <p>I created a Bullet Class and want the Spaceship to be able to shoot Bullets. The Problem is: There a no Errors but also, no Bullets. I'm not totally sure if they are just not drawn or I just can't see them.</p> <p>If you could help me, you would really help me a lot:</p> <p>The relevant Files (main.js, held.js) i've uploaded to my Git: <a href="https://github.com/nemoxdelight/First_Game" rel="nofollow">https://github.com/nemoxdelight/First_Game</a></p> <p>Sorry for the German Comments, but it makes it a lot easier for me sometimes :P</p> <p>I think the Problem is somewhere in here in the held.js:</p> <pre><code>//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 &lt; 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 &lt; this.kugeln.length; i++) { if (this.kugeln[i].held_x &gt;= 0) { this.kugeln[i].draw(); } } } Held.prototype.schussCheck = function() { if (this.leerTaste &amp;&amp; !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 &gt;= 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 &gt; width) { this.drawX = -20; } }; Kugel.prototype.geschossen = function(startX, startY) { //Sagt an was erlaubt ist. this.drawX = startX; this.drawY = startY; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload