Search the Community

Showing results for tags 'remove array item'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Facebook Instant Games
    • Coding and Game Design
  • Frameworks
    • Phaser 3
    • Phaser 2
    • Pixi.js
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Twitter


Skype


Location


Interests

Found 1 result

  1. Hi guys, I'm trying to optimize my game removing unused array objects. This code decrease the "Y" position of each array's objects, if y is minor than "-150", it removes the element. for (var a=0; a < testArray.length; a++) { if(testArray[a] != 'unload'){ if(testArray[a].position.y > '-150' ){ bonuSpeed = 130 + (5 * timerSpeed); speedRandom = Math.floor(Math.random() * 280) + bonuSpeed; testArray[a].position.y -= speedRandom * game.system.delta; // move sprite using delta time } else { //alert(testArray.length); testArray[a].remove(); testArray[a] = 'unload'; } } }Unfortunately, "testArray[a].remove();", doesn't work as expected so my first optimization was to change the value of testArray[a] with: testArray[a] = 'unload';So I can check if the element is equal to "unload" and skip the y variation. This is quite good, but when the array length is major than 500 some graphic problem arrives (like fps drop). So I tried to remove the unused testArray[a] with a function: function removeByIndex(arr, index) { //alert(testArray.length); arr.splice(index, 1); //alert(testArray.length);} for (var a=0; a < testArray.length; a++) { if(testArray[a] != 'unload'){ if(testArray[a].position.y > '-150' ){ bonuSpeed = 130 + (5 * timerSpeed); speedRandom = Math.floor(Math.random() * 280) + bonuSpeed; testArray[a].position.y -= speedRandom * game.system.delta; // move sprite using delta time } else { //alert(testArray.length); testArray[a].remove(); removeByIndex(testArray, a); } } }and partially works, the testArray length decreases but the game freezes. I think the problem is that the "For" checks the testArray's length, and I change this length during the cycle. Can anyone help me with this problem? Thank you ^^