Thunderfist

Map not appearing

Recommended Posts

My game isn't loading the map I made using tiled. The file, testroom1.json, is called properly, but something in my game.js is keeping the game from loading the map itself.

var RPG = RPG || {};

RPG.GameState = {
    
    init: function (currentLevel) {
        //Needed to keep track of the level
        this.currentLevel = currentLevel || currentLevel === 'testroom1';
        
        //movement speed constants
        this.PLAYER_SPEED = 90;
        
        //no gravity in top down games
        this.game.physics.arcade.gravity.y = 0;
        
        //keyboard cursors for input
        this.cursors = this.game.input.keyboard.createCursorKeys();
    },
    create: function () {
        this.Game.onscreenControls = this.game.plugins.add(Phaser.Plugin.OnscreenControls);
        
        this.loadLevel();
    },
    update: function () {
        
    },
    loadLevel: function () {
        //create the tilemap object
        this.map = this.add.tilemap(this.currentLevel);
        
        //Join the tile images to the .json data
        this.map.addTilesetImage('tileset', 'tilesheet');
        
        //create tile layers
        this.backgroundLayer = this.map.createLayer('backgroundLayer');
        //this.collisionLayer = this.map.createLayer('collisionLayer');
        
        //set background to the back of screen
        this.game.world.sendToBack(this.backgroundLayer);
        
        //Collision Layer... if only I made it earlier
        //this.map.setCollisionBetween(1, 16, true, 'collisionLayer');
        
        //resize the world to fit the layer
        //this.collisionLayer.resizeWorld();
    },
    gameOver: function () {
        this.game.state.start('Game', true, false, this.currentLevel);
    }
};

I never made the collision layer. I plan on doing that AFTER getting the map to appear first.

Does anyone have any advice on how to tackle this?

Share this post


Link to post
Share on other sites

I just tried that, and now my browser's console says that the .csv file isn't found. How do I find it?

 

UPDATE: I got the .csv file to be found. Now I'm getting an error about the onscreenControls.js that game.js is trying to use. It says 'cannot set property 'onscreenControls' of undefined. How do I deal with this?

Edited by Thunderfist

Share this post


Link to post
Share on other sites

I think I found the big error! It's saying that the program can't read property width of undefined for this.loadLevel in my create function, and this.add.tilemap in the loadLevel function.

 

What do I do?

Share this post


Link to post
Share on other sites

Cannot read property 'loadTilesetImage' of undefined 

                  at Object.preload (game.js:20)

 

All that function is doing is trying to load the map terrains from the preload.js. I'm worried that I won't finish this project before May, and I'm still stuck on this part!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.