Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You've got a few problems:</p> <ol> <li><p><strong><code>Explosion.Loop</code> does not exist</strong>; in normal classical languages, your error would be known as "trying to call an instance method as if it were static." What you could do is instead pass <code>Explosion.prototype.Loop</code> or <code>this.Loop</code>, but that's no good either: JavaScript's <code>this</code> is dynamic and you'll end up trying to get and set properties on <code>window</code> rather than your object.</p> <p>What you need to do is use <code>this.Loop</code>, but make sure the <code>this</code> isn't lost. On newer browsers, that can be done with <code>bind</code><sup>1</sup>:</p> <pre><code>setTimeout(this.Loop.bind(this), 500); </code></pre> <p><sup>1</sup> If they're new enough to support <code>canvas</code>, they probably support <code>bind</code>.</p></li> <li><p><strong><code>setTimeout</code> will only call your function once</strong>; if you want it to be called every half a second rather than only once half a second from now, you'll need to use <code>setInterval</code> instead.</p></li> <li><p><strong>Accessing instance variables as if they were local variables.</strong> In several places (for example, <code>frame</code> in <code>Loop</code>), you're accessing <code>frame</code> like this:</p> <pre><code>frame++; </code></pre> <p>Unfortunately, <code>frame</code> is not a local variable; it's a property of <code>this</code>. Unlike some other languages, you have to explicitly qualify it:</p> <pre><code>this.frame++; </code></pre> <p>As previously mentioned, <code>frame</code> is not the only variable with this problem.</p></li> </ol>
 

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