Jump to content

Problem with load tile to the tilemap


P4nch0
 Share

Recommended Posts

Hi everyone!

 

I have a problem with load tile to the map.

 

In my project when player click on the map, tile.x and tile.y i saveing in data base, and them when i start game tiles are loading to the map.

 

When i load tile when player click, everything is okay, and it is colide with player and added object.

if(TopDownGame.level == "ogrod1"){if (przedmiotwybrany == "lopata") {//this.map.tilesets[2].setImage(this.game.cache.getImage("gamesrodekdom"));tilex = this.backgroundlayer.getTileX(this.game.input.activePointer.worldX);tiley = this.backgroundlayer.getTileY(this.game.input.activePointer.worldY);idtile = 518;layer = "backgroundLayer";this.map.putTile(idtile, tilex, tiley, this.backgroundLayer)this.wyslijdanemapa();console.log(przedmiotwybrany);}else if (przedmiotwybrany == "siekiera"){tilex = this.backgroundlayer.getTileX(this.game.input.activePointer.worldX);tiley = this.backgroundlayer.getTileY(this.game.input.activePointer.worldY);idtile = 171;layer = "backgroundLayer2";this.map.putTile(idtile, tilex, tiley, this.backgroundLayer2)this.wyslijdanemapa();console.log(przedmiotwybrany);}else{tilex = this.backgroundlayer.getTileX(this.game.input.activePointer.worldX);tiley = this.backgroundlayer.getTileY(this.game.input.activePointer.worldY);idtile = 812;layer = "blockedLayer";this.map.putTile(idtile, tilex, tiley, this.blockedLayer)this.wyslijdanemapa();console.log(przedmiotwybrany);}} 

But when i restart the game, and them load tile from database they are loaded but issnt collide with player..

     if(TopDownGame.level == "ogrod1"){                  for (var i = 0; i < Tablicawiersze; i++) {              var iidtile = Tablica[i][0];  var ttilex = Tablica[i][1];  var ttiley = Tablica[i][2];  var llayer =  Tablica[i][3];    this.map.putTile(iidtile, ttilex, ttiley, llayer)   }         }

Anyone have idea why?

Greets. :)




			
		
Link to comment
Share on other sites

Anyone have idea?

I am working with it all week and dont have solution.

Maybe it have a trouble with add body to tile?

 

When i am trying to add body to the tile:

 

   for (var i = 0; i < Tablicawiersze; i++) {                 var iidtile = Tablica[i][0];   var ttilex = Tablica[i][1];   var ttiley = Tablica[i][2];   var llayer =  Tablica[i][3];               var tile= this.map.putTile(iidtile, ttilex, ttiley, llayer);     this.game.physics.arcade.enable(tile);         this.mapagroup =  this.game.add.group(); this.mapagroup.add(tile);         this.mapagroup.enableBody = true;                    } 

 

I have a wrong:

 

TypeError: child.setStageReference is not a function

I dont have idea why when i am click sprite is colliding with tile, but when load it from database, tile is not colliding.

Please help.

 

 

Link to comment
Share on other sites

Loading data from data base gived me few days finding wrong again.

 

The wrong was because data loading from database was string..

How game loaded tile to the good coordinates? - i dont have idea, but that was point what i dont mean..

Parse data to the integer is solution:

 

 this.map.putTile(parseInt(iidtile), parseInt(ttilex), parseInt(ttiley), llayer) 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...