Search the Community
Showing results for tags 'getIndex'.
-
Hello, I'm using BSP to build an array for level generation. For now, the 2d array contains either a 0 or 1, for empty space or where a tile should be. I'm then trying to use the array as a string to pass into the tilemap function. However, none of the methods I've tried for generating the tilemap are working. The closest I've been able to get is throwing an error in phaser.js's getIndex function, saying that the "location" property is undefined. That seems like this issue, but that's been reported as fixed. I'm using version 2.4.4 of Phaser. I saw another thread that said 0 shouldn't be used, because when Phaser loops through the data, it only looks for things greater than 0. I changed it to use 1 for empty space, and 12 for a tile (just to pick something from my tilesheet), but that made no difference. Someone please tell me what I'm doing wrong! Here is the tilemap I slapped together for testing: Here's the code I'm using (stripping out all of the level generation stuff): var TILE_SIZE = 32;var WIDTH_RATIO = 0.45;var HEIGHT_RATIO = 0.45;var ITERATIONS = 4;var mainRoom = undefined;var levelArr = [];var map;var BSP2 = function (){ this.levelWidth = 0; this.levelHeight = 0; this.tilesPerRow = 0; this.tilesPerColumn = 0; this.roomTree = undefined; this.rooms = [];};BSP2.prototype = { init: function(levelWidth, levelHeight) { this.levelWidth = levelWidth; this.levelHeight = levelHeight; this.tilesPerRow = levelWidth/TILE_SIZE; this.tilesPerColumn = levelHeight/TILE_SIZE; mainRoom = new RoomContainer(0, 0, this.levelWidth, this.levelHeight); levelArr = new Array(this.tilesPerColumn); for(var i = 0; i < this.tilesPerColumn; i++) { levelArr[i] = new Array(this.tilesPerColumn); } for(var c = 0; c < this.tilesPerColumn; c++) { for(var r = 0; r < this.tilesPerRow; r++) { levelArr[c][r] = 1; } } }, preload: function() { //console.log("bsp2.js - preload()"); game.load.image('img_leveltiles_test', 'leveltiles_test.png'); }, create: function() { //console.log("bsp2.js - create()"); game.add.sprite(0, 0, 'bg_background'); ... this.drawTiles(); }, drawTiles: function() { game.load.tilemap('tilemap', null, [levelArr.toString()], Phaser.Tilemap.TILED_JSON); map = game.add.tilemap('tilemap'); map.addTilesetImage('tileimage', 'img_leveltiles_test', TILE_SIZE, TILE_SIZE); map.create('firstlevel', this.levelWidth/TILE_SIZE, this.levelHeight/TILE_SIZE, TILE_SIZE, TILE_SIZE); }};And this is what a typical array-to-string setup looks like: