0
\$\begingroup\$

Jsfiddle : http://jsfiddle.net/seekpunk/6eeKH/15/

the code :

if (this.collection.length > 0) {
    if (((this.collection[0].blockX + this.collection[0].blockW) >= cw) 
       || (this.collection[0].blockX <= 0)) {
        this.collection[0].blockSpeed *= -1;
    }
    this.collection[0].blockX += this.collection[0].blockSpeed;
}

the first block from top is drawn twin and i can't figure out why i guess the problem is in drawing the levels can someone please help me figure out what i did wrong in my code

\$\endgroup\$
  • 1
    \$\begingroup\$ "How to debug my code" questions are not considered good questions on the site. Please edit the question to describe what algorithm you want to implement and why you think it's not working. \$\endgroup\$ – MichaelHouse Feb 3 '14 at 14:27
  • \$\begingroup\$ updated my question please check \$\endgroup\$ – Sora Feb 3 '14 at 14:48
0
\$\begingroup\$

You're adding blocks using addBlocks method every frame in function Level1, all your blocks are duplicated loads of times. In Blocks.draw(), print the size of the collection and you'll see what I mean.

Make sure you set up your level once, then change the state of it, do not add all the blocks on every frame.

\$\endgroup\$
  • \$\begingroup\$ thank you i followed your instruction and this is the new jsfiddle : jsfiddle.net/seekpunk/6eeKH/17 the levels are drawn fantastically thank you for your help \$\endgroup\$ – Sora Feb 3 '14 at 20:06
  • \$\begingroup\$ Glad I could help. \$\endgroup\$ – bornander Feb 4 '14 at 8:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.