Jump to content

Franzeus

Members
  • Posts

    7
  • Joined

  • Last visited

Everything posted by Franzeus

  1. Ok thank you! Then I will loop through the whole tilemap data. I wonder if there will be something again like the createFromObjects function, which basically did everything for me in the past. You are also right about the performance of the (entire) tile image, but for now I am just prototyping with (very ugly) tiles ;)
  2. Or am I too early for this to work?! Would love to do it with Phaser3 - especially because I like the multiple camera and path feature!
  3. Hi there, I wanted to start to create a 2D top down game with Tiled and Phaser3 but I am running into some issues. I created some tile layers (wall, floor tiles) and object layers (e.g. agent) and exported it as JSON. My preload function: this.load.json('map', 'assets/tilemaps/0.json'); // Each 32px of size this.load.image('wall', 'assets/images/game/tiles/wall.png'); this.load.image('floor', 'assets/images/game/tiles/floor.png'); this.load.image('agent', 'assets/images/game/agents/agent_0.png'); My create function: var tileSize = 32; var map = this.cache.json.get('map'); var mapWidth = map.width; var mapHeight = map.height; var wall_layer_data = map.layers[0].data; var walls_tilemap = this.add.staticTilemap(wall_layer_data, 0, 0, tileSize, tileSize, mapWidth, mapHeight, 0, 'wall'); Map json (Created with Tiled Version 1.0.3) : Is basically an array of layers: "layers":[ { "data":[0, 0, 2], // etc "height":17, "name":"walls", "opacity":1, "type":"tilelayer", "visible":true, "width":29, "x":0, "y":0 }, { // Next layer for tiles and object layers } Now my issue is that the wall tiles are drawn everywhere (whole map size and 0 and 2 are basically a wall tile). I saw in the examples that all tiles are now in one layer and not separated ones and that all images are also in one file. Is there a way to have multiple layers and separated image files? Furthermore is there still a way to extend a Sprite and then use it with createFromObjects()? Does that method still exists? My goal is to render a json file I created in Tiled. Some of them are simply static tiles, some of them with collision and some of them have extended functionality and therefore need their own Sprite class. Thank you very much!
  4. Why don't you use the AirConsole API? http://developers.airconsole.com
  5. Perfect, its exactly what I wanted! Didn't really understand the objects layer in Tiled var Tower = function () { Phaser.Sprite.apply(this, arguments); }; Tower.prototype = Object.create(Phaser.Sprite.prototype); Tower.prototype.constructor = Tower; // Creation: this.towers_group = this.phaser.add.group(); this.towers_group.classType = Tower; this.towers_group.enableBody = true; // name, gid, key, frame, exists, autoCull, group, CustomClass, adjustY this.map.createFromObjects('Object Layer 1', 1, 'tower', 0, true, false, this.towers_group, Tower); this.towers_group.setAll('body.immovable', true); this.towers_group.setAll('body.moves', false);
  6. Ok thanks, but how do I access "sprite"? I think what I am missing is how to access the created Sprites (or Tileset objects) which were generated by the json-data. Is the Tilemap.createFromObjects something which could work?
  7. Hi devs, I got some questions about the way to work with phaser and tiled and I haven't really found answers yet and hope that you guys can help me My goal is to create a simple tilebased game (top down view) with walls, towers and later add player objects. I am using Tiled to create the map. The tilesize is 16x16. Using Arcade Physics for collision. # Map (16x16) and rendering My tower-sprites are 32x32px. So basically 2 columns, 2 rows. Rendering-Problem: The towers (32x32) have some kind of an offset when I place them into the 16x16 grid. If I import them in Tiled and specify they are 16x16, then it works. I tried to set the TILE RENDER OPTION to "Left Up" but it didn't help. What am I doing wrong here? Collision-Problem: Only the top left cell of the tower seems to have a bounding box for collision. The other cells are ignored. Is there a way to tell phaser that the tile is actually not 16x16, but 32x32 and occupies more cells? # Map creation: this.map = this.phaser.add.tilemap('map'); this.map.addTilesetImage('wall'); this.map.addTilesetImage('tower'); this.layer = this.map.createLayer('World'); # Tower JSON { "columns":2, "firstgid":2, "image":"..\/game\/tower.png", "imageheight":32, "imagewidth":32, "margin":0, "name":"tower", "spacing":0, "tilecount":4, "tileheight":16, "tileproperties":{}, "tilewidth":16, } # Object creation The players are not included in the tilemaps json-data but created "dynamically" with their own class (extends Sprite): Unit = function (index, game, opts) { opts = opts || {}; var x = opts.x || game.world.randomX; var y = opts.y || game.world.randomY; this.game = game; // etc ... Phaser.Sprite.call(this, game, x, y, 'player'); }; Unit.prototype = Object.create(Phaser.Sprite.prototype); Unit.prototype.constructor = Unit; I wonder how it would work to create a Tower class for each tower-tile I encounter. Basically link tiles to an object: // Something like: for each tile: if tile == 'tower' new Tower() And when a player collides with a tower I can call my own defined methods like: Tower.collidesWith(player_sprite) Thank you very much!
×
×
  • Create New...