P4nch0 Posted December 7, 2015 Share Posted December 7, 2015 Hi everyone! In my project i have screen of the gampe when map was create in tile map editor. Now i want change some element on the map after any action.For example when the player use tool, some parts of ground will change for another tile elements. Is any way to get some part of map and change it for another tile? I found function what can help, but i dont know how to use it in my project.My project You can see on lifetime.cba.pllogin test password test Thanks for any ideas! Link to comment Share on other sites More sharing options...
P4nch0 Posted December 7, 2015 Author Share Posted December 7, 2015 On this page:http://gamedevelopment.tutsplus.com/tutorials/parsing-and-rendering-tiled-tmx-format-maps-in-your-own-game-engine--gamedev-3104is good tutorial how to implement GID, but i dont know about i must do all steps?I need XML? I render map by this way: createItems: function() { //create items this.items = this.game.add.group(); this.items.enableBody = true; var item; result = this.findObjectsByType('item', this.map, 'objectsLayer'); result.forEach(function(element){ this.createFromTiledObject(element, this.items); }, this); }, Link to comment Share on other sites More sharing options...
P4nch0 Posted December 7, 2015 Author Share Posted December 7, 2015 I found fine tutorial how to get properties of any tile, but it is still very hard to me.. http://www.raywenderlich.com/29460/collisions-and-collectables-how-to-make-a-tile-based-game-with-cocos2d-2-x-part-2 Maybe anyone can show some examples how to start to do it? Thanks in advance Link to comment Share on other sites More sharing options...
Skeptron Posted December 8, 2015 Share Posted December 8, 2015 Check this Phaser example for tile replace : http://phaser.io/examples/v2/tilemaps/replace-tiles P4nch0 1 Link to comment Share on other sites More sharing options...
P4nch0 Posted December 8, 2015 Author Share Posted December 8, 2015 Thanks for answer. I found fine method to change tile:http://docs.phaser-polska.pl/Phaser.Tilemap.html#replaceI am trying that:var tile = this.map.getTile(21,1); this.map.putTile(12, 14); but id doesnt work, nothing happens. When i do it with removeTile it works, tile is removing. Anyone can help? Link to comment Share on other sites More sharing options...
P4nch0 Posted December 8, 2015 Author Share Posted December 8, 2015 I have that version:var tile = this.map.getTile(21,1); this.map.putTile(this.tile,12, 14);puttile is working because on screen appear white tile, but why now tile get from gettileWorldXY? Link to comment Share on other sites More sharing options...
P4nch0 Posted December 8, 2015 Author Share Posted December 8, 2015 Now i am now:var tile = this.map.getTile(21,1); this.map.putTile( 5 ,12, 14)5 is a number of tile on map. But how i can add image to variable, and them change tile for this image from variables? Link to comment Share on other sites More sharing options...
ekeimaja Posted December 9, 2015 Share Posted December 9, 2015 But how i can add image to variable, and them change tile for this image from variables? I would probably make it like this. Fix me if I am wrong. this tile = this.game.add.image('yourimage', x, y); P4nch0 1 Link to comment Share on other sites More sharing options...
Skeptron Posted December 9, 2015 Share Posted December 9, 2015 Why don't you do map.replace(1, 2); just like in the example I pasted? P4nch0 1 Link to comment Share on other sites More sharing options...
P4nch0 Posted December 9, 2015 Author Share Posted December 9, 2015 Yours example Was fine and thanks, but i want get tile from other file than map. For example when player use tools, i want to get tile from other file and paste it on the map.But i must try how to get tile or image from other file to variable and this paste to the map. When i use replace i must have this image or tile on the map. Thanks for interest. Link to comment Share on other sites More sharing options...
Skeptron Posted December 9, 2015 Share Posted December 9, 2015 Why not put all these images in the tileset? They don't need to be displayed at first, they just need to belong to the tileset. So just put them in, and then whenever you need them it's gonna be easy to swap the tiles. P4nch0 1 Link to comment Share on other sites More sharing options...
P4nch0 Posted December 9, 2015 Author Share Posted December 9, 2015 Can You tell me more how put this images in the tileset and dont display them?That can be good idea, them it will be easy to change. Link to comment Share on other sites More sharing options...
ekeimaja Posted December 9, 2015 Share Posted December 9, 2015 Have you looked here? http://phaser.io/examples/v2/category/tilemaps P4nch0 1 Link to comment Share on other sites More sharing options...
P4nch0 Posted December 9, 2015 Author Share Posted December 9, 2015 I will check it, thanks That is a fine project to talk about this, if YOu have more ideas to it please write You can check all of it on:lifetime.cba.pl login testpassword test then click "graj" to load screen Link to comment Share on other sites More sharing options...
P4nch0 Posted December 9, 2015 Author Share Posted December 9, 2015 I think about Yours methods but this is not that wat i want. When i add to the game tile and dont display it, my map will be smaller, tell me if i am wrong. I dont have idea how to add tile from other file.Only idea what i have is to add it as sprite: var tile=image... var add=this.add.sprite(this.input.activePointer.x + this.camera.x, this.input.activePointer.y + this.camera.y, tile); Do you thin it will be good solution? When i add sprite to tile on map it not will be double and the game not will be burdened? Maybe someone have idea how to change tile from other file/image, so tell me pls Link to comment Share on other sites More sharing options...
P4nch0 Posted December 9, 2015 Author Share Posted December 9, 2015 Hi! I found answer to my problem. It Was very easy..tilex = this.backgroundlayer.getTileX(this.game.input.activePointer.worldX);tiley = this.backgroundlayer.getTileY(this.game.input.activePointer.worldY);this.map.putTile(494, tilex, tiley)}I think about number 494 is index of tile on the map, but this is index of tile on tileset from my map was created and there are tiles what i can add to the map But now i have one question else.put tile is getting tile from frist tileset what i used to create map, but how to change tileset to other what wah using to create map? in my map i have 3 tileset images, but now i can get tile only from first, how i can change it? Link to comment Share on other sites More sharing options...
P4nch0 Posted February 20, 2016 Author Share Posted February 20, 2016 Hi everyone. I want to refresh the topic. I have a map made in tileeditor of multi tileset. When player click on map i want to att tile this method: putTile(tile, x, y, layer). TIle is a number tile on tileset, but is any way to chose from which tileset get tile? Please help and give any ide ho to do that Link to comment Share on other sites More sharing options...
Recommended Posts