Jump to content

How can I extend my tiled map without tiledmap editor and add object layer


abdul
 Share

Recommended Posts

I am testing a racing  car game. For that I make my road in tiled map editor and using its json file in  phaser. It is 50 tiles in height. Now I want to extend my map. I have two options , extend it through phaser or make whole extended map in tiled map editor. Which one is better and how can I extend it through phaser ? I have no idea about this.

I also want to add an object layer on my   background layer,  so that my car collides with other objects which will be on my background layer. I have already searched object layer problem in this forum, but not satisfied.

I am also attaching files , may be I am  not clearing my question...

plz help me out..test game.zip

Link to comment
Share on other sites

How do you want to extend your map? If you want to programmatically add more to the map, your best route is probably to generate the JSON data the TileMap is expecting within your game, but this won't be trivial. I think for the moment you'd be better off creating your full track in Tiled, including all of the outside areas of the track that a player would be able to see.

Link to comment
Share on other sites

I make my whole map in tiled, and it has 2 layers. Now when I move my car, it only covers few distance and then stop, I don't know why it is not covering full map. I am attaching files test game.zip I don't know what is missing or wrong in it..

 

and second thing is that, in first layer I have road and in second layer  I have footpath, I  want that car drives on road and collide with footpath. but what should I do for that ?  I set collision of my car with both layers, should I make my second layer object layer ? or there is any other way to handle this.

 

Link to comment
Share on other sites

For your first question, the problem was you were calling resizeWorld twice, so change your onCreate function to this:

  function onCreate() {           // game.stage.backgroundColor = '#6b6b9d';            map = game.add.tilemap('map'); //preloaded tilemap      map.addTilesetImage('roadNS','tileset'); // preloaded tileset image      map.addTilesetImage('roadNE','tileset2'); // preloaded tileset image      map.addTilesetImage('roadNW','tileset3'); // preloaded tileset image      map.addTilesetImage('roadSE','tileset4'); // preloaded tileset image      map.addTilesetImage('roadSW','tileset5'); // preloaded tileset image      map.addTilesetImage('roadNEWS','tileset6'); // preloaded tileset image      layer1 = map.createLayer('background'); //default name of the layer in map      layer2 = map.createLayer('Tile Layer 2'); //default name of the layer in map            layer1.resizeWorld(); // sets the world size to match the size of the layer            map.setCollisionBetween(0,382,true,layer1);      map.setCollisionBetween(0,306,true,layer2);            layer1.debug = true;      layer2.debug = true;            //game.physics.startSystem(Phaser.Physics.P2JS);      game.physics.startSystem(Phaser.Physics.ARCADE);      car = game.add.sprite(110,game.world.height-100,'car');      // Set the rotation point of the car to be dead-centre, otherwise the car will turn      // strangely and the collision box will be less predictably placed.      car.anchor.set(0.5);      car.angle = -90; // point the car up            //game.physics.p2.enable(car);      game.physics.arcade.enable(car);      // Because of limitations with Arcade physics and rotation we need to ensure the body is      // square. This means the collisions will be more reliable regardless of the orientation      // of the car.      car.body.setSize(32, 32);      car.body.maxVelocity.setTo(MAX_SPEED, MAX_SPEED ); //x,y      car.body.drag.setTo(DRAG,DRAG);            cursors = game.input.keyboard.createCursorKeys();      game.camera.follow(car);  }

I'm afraid I can't help much with the TileMap specific questions as I've not used TileMaps myself yet.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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