Jump to content

trouble at using createFromObjects() in phaser


brookslee
 Share

Recommended Posts

Hi all,

I am really lost at how to use createFromObjects() in phaser.The object that I have used in the map is a part of a tileset but my code displays the entire tileset(which I do not want).The object layer is named as "Object Layer 1" and the tileset is "drink".My json file is attached.My code(as of now )is:

var game=new Phaser.Game(800,600,Phaser.AUTO,'',{ preload:preload,create:create,update:update });

function preload(){
    game.load.tilemap('map','maze2.json',null,Phaser.Tilemap.TILED_JSON);
   
    game.load.image('rocks','oppcastle-mod-tiles.png');
    game.load.image('drinks','Food and drink package.png');
    game.load.image('dude','index.png');

}

var map;
var layer;
function create(){

    game.physics.startSystem(Phaser.Physics.ARCADE);
    game.stage.backgroundColor = '#787878';
    map = game.add.tilemap('map');

    map.addTilesetImage('oppcastle-mod-tiles','rocks');    

    layer = map.createLayer('Tile Layer 1');
    //map.setCollisionBetween(1,30,true,'layer');    

    layer.resizeWorld();
    layer.wrap = true;
    

    //creating items
    items=game.add.group();
    items.enableBody=true;
    map.createFromObjects('Object Layer 1',183,'drinks',0,true,false,items);
    player=game.add.sprite(0,game.world.height/2,'dude');
}

function update(){

}

Also,I will really grateful if you could tell me how should I go about setting collision between "dude" and "drink"(I do not understand the parameters).Please please please help.I am going nuts over it for quite a long now.Thanks in advance.

Regards,

Brooks

 

 

maze2.json

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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