Jump to content

  • Log In with Google      Sign In   
  • Create Account

How to redefine variable in Javascript


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
22 replies to this topic

#21 EmployeeNumber8   Crossbones+   -  Reputation: 1103

Like
0Likes
Like

Posted 27 February 2013 - 03:16 PM

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!



Sponsor:

#22 Patriarch K   Members   -  Reputation: 212

Like
0Likes
Like

Posted 27 February 2013 - 03:34 PM

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?

Edited by Patriarch K, 27 February 2013 - 03:35 PM.


#23 EmployeeNumber8   Crossbones+   -  Reputation: 1103

Like
1Likes
Like

Posted 28 February 2013 - 07:31 AM

That is something you need to use the debugger for. 

 

Here is how it is done in Chrome






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS