简体   繁体   English

Javascript功能仅适用于画布游戏

[英]Javascript function just not working for canvas game

I'm creating a canvas game (the concept is a side scrolling endless games). 我正在创建一个画布游戏(概念是侧面滚动无尽的游戏)。 I'm trying to make power-ups so I have a main game JS file along with a powerup.js among others. 我正在尝试加电,因此我拥有一个主要的游戏JS文件以及powerup.js等文件。 At the moment I'm concentrating on my invincibility power up. 此刻,我专注于增强我的无敌能力。 I've created some simple code which in theory should work: 我创建了一些简单的代码,这些代码在理论上应该可以工作:

In the powerup.js 在powerup.js中

function powerUpInvincibility() {
    invincible = true;
    //window.setInterval(powerUpInvincibilityReset, this.powerUpTime[0]);
}

function powerUpInvincibilityReset() {
    jet1.invincible = false;
}

I set the invincible variable in the main js but they are all linked, I've got code in all the JS files working but even when I call the powerUpInvincibility function in Chrome's Console the variable doesn't change. 我在主js中设置了invincible变量,但它们都是链接的,所有JS文件中都有代码可以工作,但是即使我在Chrome浏览器的控制台中调用powerUpInvincibility函数,该变量也不会更改。

I've tried making it a variable for the jet and the powerup but that doesn't work either and I've checked for any spelling mistakes several times. 我尝试将其设置为喷气机和加电装置的变量,但这也不起作用,并且我已经多次检查了任何拼写错误。

I'm lost, any suggestions? 我迷路了,有什么建议吗?

Ok sorry everyone! 好的,对不起大家! The actual problem was that one of my powerUp functions tried to access a this variable when it wasn't a powerUp.prototype function. 实际的问题是,当我的powerUp函数不是powerUp.prototype函数时,它试图访问此变量。 Thanks for the answers! 感谢您的回答!

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM