• Content count

  • Joined

  • Last visited

About RetroGameDev

  • Rank

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. RetroGameDev

    Making a level through an array

  2. RetroGameDev

    Making a level through an array

    Hi, I followed lessMilks tutorial ( on how to make a platformer and they use an array with two for loops to create the level from the tutorial - // Design the level. x = wall, o = coin, ! = lava. var level = [ 'xxxxxxxxxxxxxxxxxxxxxx', '! ! x', '! o x', '! o x', '! x', '! o ! x x', 'xxxxxxxxxxxxxxxx!!!!!x', ]; / Create the level by going through the array for (var i = 0; i < level.length; i++) { for (var j = 0; j < level[i].length; j++) { // Create a wall and add it to the 'walls' group if (level[i][j] == 'x') { var wall = game.add.sprite(30+20*j, 30+20*i, 'wall'); this.walls.add(wall); wall.body.immovable = true; } // Create a coin and add it to the 'coins' group else if (level[i][j] == 'o') { var coin = game.add.sprite(30+20*j, 30+20*i, 'coin'); this.coins.add(coin); } // Create a enemy and add it to the 'enemies' group else if (level[i][j] == '!') { var enemy = game.add.sprite(30+20*j, 30+20*i, 'enemy'); this.enemies.add(enemy); } } } I have used this to create my own level but have run into some problems and was wondering if anyone knew how to help. 1) I set my game bounds to 3000, 480, then adjusted the size of the array and the position of platforms/player/enemies etc so it all fits nicely and spaced correctly. I have noticed that each space in the array is the equivalent of 30px, 30px. Would it be possible to change this? As I can't find a way to do this. 2) I wanted to potentially make a small level editor by making adding the platforms etc, enabling drag and setting them into position (which works great). But I have no idea how to capture the position of the platform in the array. I can get the coords of the platform from within the level itself but I don't know how to reference the array. Ideally, this would work by adding and setting the platform then somehow pushing the letter ('x' from the example above) to the array. If anyone has any ideas that would be great because I am quite stumped at the moment. 3) Lastly, is making a level like this viable? I am only running this game locally and I'm having no performance issues so far. I'm quite happy creating the levels in the ide but thought I'd ask the community if they had any experience with this. Thank you, RGD