Jump to content

Can't load tileset--function not found


Recommended Posts

After following the first tutorial I've been trying my hand at a simple platformer.  I used a very simple png and map editor to create the first level and I looked at a few tutorials online to figure out how to import created levels.



I came up with this:

   preload: function(){        this.game.load.image('sky', 'assets/BackgroundGradient.png');        this.map = this.game.load.tilemap('map', 'assets/level1.json', null, Phaser.Tilemap.TILED_JSON);        this.game.load.image('tiles', 'assets/Dirt-Grass-1.png');        //this.game.load.tileset('tiles', 'assets/Dirt-Grass-1.png', 64, 64);  Commented out because of error.        this.map.addTileSetImage('tiles','tiles');                            }

but when I try to run it, I come across these errors in firefox and chrome respectively.

this.map.addTileSetImage is not a functionUncaught TypeError: Object [object Object] has no method 'addTileSetImage' 

I run into these errors both when I'm trying to use game.load.tileset and this.map.addTileSetImage.  I know that the objects exist because I have no problem calling other methods on them.


What am I doing wrong?  The only thing I can think of is that I'm not passing the correct paramaters.  In which case I'm not sure what I should be passing instead.


Link to comment
Share on other sites

Here is the correct way to use the APIs.

map must contain the object returned by game.add.tilemap('map');


function preload(){


          game.load.tilemap('map', 'assets/tilemaps/map.json', null, Phaser.Tilemap.TILED_JSON);

         // to load the tileset

         game.load.image('tiles', 'assets/tilemaps/super_mario.png');




function create(){

        // Adds map to the game

        map = game.add.tilemap('map');
        map.addTilesetImage('SuperMarioBros-World1-1', 'tiles');



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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