如何查看项目符号I'我在画布上拍摄
How to see the Bullets I'm shooting on Canvas?
我的画布再次出现问题。我目前正在编写一个Javascript Space Shooter。
我创建了一个子弹类,希望太空船能够发射子弹。问题是:没有错误,但也没有项目符号。我不完全确定它们是没有画出来还是我看不见它们。
如果你能帮助我,你真的会帮我很多:
我上传到Git的相关文件(main.js,holded.js):https://github.com/nemoxdelight/First_Game
很抱歉收到德国人的评论,但这有时会让我更容易:p
我认为问题就在这里。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;
}
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_x
的字段,至少在Kugel
的构造函数中没有。也许你想用之类的东西
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();
}
}
}
顺便问一下,你真的是指main.js line 46
中的if(laeuft = true){
吗?
相关文章:
- 正在将数据主题添加到所有项目
- 动态地改变“”的URL;添加新项目”;链接使用javascript/jquery
- 如何检查管道中未定义的项目
- 查看JS对象的所有键,甚至是getter定义的键
- 有没有一种方法可以添加相同的项目val=“0”;4〃;到JavaScript中数组的每个对象
- 学生搜索项目jquery/javascript
- 如何获取不属于我项目的上一页的URL
- Dojo:访问dijit.form.Select中单击的项目
- backbone.js可以't传递集合中的模型项's查看项目's视图
- 如何使用仅显示/查看两个项目的甘特图
- 如何查看项目符号I'我在画布上拍摄
- 绑定到项目查看更改事件
- 加载更多项目,而无需滚动或按“查看更多”,就像在Facebook中使用JS一样
- 跟踪访问者上次查看的项目
- 单击列表中的项目->查看详细信息但没有输出?Firebase.child失败:第一个参数是无效路径
- 如何单击列表中的项目并在新页面中查看该项目?AngularJS和Ionic
- 查看购物车中的项目,购物车是一个对象数组
- 我如何允许点击每个项目/帖子,然后在一个新的屏幕上查看它
- 查看文件更改时出错:EMFILE"初始化react-native项目时
- 在$http上检索数组并在离子列表的离子项目中查看