How to redefine variable in Javascript

Started by
21 comments, last by DangerDoom 11 years, 1 month ago

Have you tried to step through the code in a debugger to see exactly where it freezes?

This may work in your browser, but I don't think it works the same in all browsers. You shouldn't use a for in loop for arrays in JavaScript. Use them to iterate properties on objects.


for(k in bullets){
          k.draw();
        }

Use this instead...


for(var i = 0; i < bullets.length; ++i){
   bullets[i].draw();
}

That probably isn't the issue, but it's something to look out for.

I'd say use the debugging tools in your browser. Set some breakpoints. You'll be able to pinpoint the exact issue and we'll be able to help you much easier!

Advertisement

I don't really know how that works. But I tried another thing and I think it works now. I changed to this: (before I had jet1.getX())


 Bullet.prototype.draw = function(){
     this.update();
      ctxBullet.drawImage(bulletImage, x, y);
   }

And I changed to this:

function loop() { 
       ctxBg.drawImage(background, 0, 0);
        jet1.draw();
        jet1.move();
          for(var i = 0; i < bullets.length; ++i){
   bullets[i].draw();
   bullets[i].move();
}

What I don't know is if I have only been drawing one picture now or is that the correct way do draw for all objects?! Could that be the solution to it?

That is something you need to use the debugger for.

Here is how it is done in

">Chrome

This topic is closed to new replies.

Advertisement