Jump to content

Search the Community

Showing results for tags 'for'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Facebook Instant Games
    • Web Gaming Standards
    • Coding and Game Design
    • Paid Promotion (Buy Banner)
  • Frameworks
    • Pixi.js
    • Phaser 3
    • Phaser 2
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
    • GameMonetize
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered
    • Marketplace (Sell Apps, Websites, Games)

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 3 results

  1. Hi Sorry if this is in the docs somewhere, but I couldn't find it. Could someone please tell me if Phaser (or possibly Brackets) is deliberately limiting the size of my loops, as I can't seem to get them to work over about 32000 iterations. I did notice that JSbin has something called "loop protection" but offers a code to turn it off. Is there a way to do this in Phaser?
  2. 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 ^^
  3. Hey guys, I'm having an odd issue. I'm trying to automatically generate a map. Here, I'm going to show the code, and then explain what happens when I run it: // This is another class and defines a room in the game Room: function(x, y, w, h) { this.x1 = x; this.y1 = y; this.x2 = x + w; this.y2 = y + h; }, // Used to create rooms (a rectangle of non-blocked tiles) on the map // SOMETHING HERE IS CRASHING createRoom: function(room) { for (var x = room.x1; x < room.x2; x=+32) { for (var y = room.y1; y < room.y2; y=+32){ // change the "true" to "false" after collision is worked out this.map.push(new this.Tile(x, y, true, true)); } } },(I'm sorry, I know this code isn't pretty) Okay, so, as you can see, a room is really just a coordinate-defined rectangle. The "map" is an array that stores "Tiles" which are coordinate-defined tiles. Whew, does that make sense? I need to go back to school for sure. Now, that for statement, I'm going to use an example: We'll assume that room.x1 = 32, ".x2 = 96, ".y1 = 32, ".y2 =96. Nice and easy. (1) In the first for statement: if 32 is less than 96; it is, so we change 32 to 64 and move on (2) In the 2nd for statement: if 32 is less than 96; it is, so we change 32 to 64 and move on (3) We append a tile to the map array with coords (64, 64), and go back to the beginning (5) In the next pass we append a tile with coords (96, 96), and go back to the beginning (6) The for statement no longer applies, so it stops. This should only run 3 times right? But it's running indefinitely and crashing my browser. Any ideas?
×
×
  • Create New...