renlok

Minimap and tilemap issues

Recommended Posts

I am trying to make a simple prototype which involves a randomly generated tilemap which I have working and a minimap. But my problem I have is the tilemap within the minimap camera doesn't zoom. The player sprite works fine but the tiles display full size. I don't know if this is a known issues or I am doing something wrong.

 

My code is 

let config = {
    width: 800,
    height: 600,
    resolution: 1,
    type: Phaser.WEBGL,
    parent: 'phaser-example',
    scene: {
        preload: preload,
        create: create,
        update: update,
        extend: {
            minimap: null,
            player: null,
            cursors: null
        }
    },
    callbacks: {
        preBoot: function () { console.log('I get called before all of the Game systems are created, but after Device is available')},
        postBoot: function () { console.log('I get called after all of the Game systems are running, immediately before raf starts')}
    }
};

let game = new Phaser.Game(config);

function preload ()
{
    this.load.image('tiles', 'assets/tileset.png');
    this.load.atlas('atlas', 'assets/tileset.png', 'assets/tileset.json');
}
let width = 40, height = 38;

function create ()
{
    let map = new MapLoader(width, height);

    this.add.staticTilemap(map.getFlatMapData(), 0, 0, 32, 32, width, height, 0, 'tiles');

    this.cursors = this.input.keyboard.createCursorKeys();

    this.cameras.main.setBounds(0, 0, 32 * width, 32 * height);

    this.minimap = this.cameras.add(200, 10, 100, 100).setZoom(0.2);

    // Add player
    let playerLocation = map.getEmptySquare();
    this.player = this.add.sprite(playerLocation.x * 32, playerLocation.y * 32, 'atlas');
    this.player.displayOriginX = 0;
    this.player.displayOriginY = 0;
}

function update (time, delta)
{
    if (this.cursors.left.isDown)
    {
        this.player.x -= 32;
        this.player.flipX = true;
    }
    else if (this.cursors.right.isDown)
    {
        this.player.x += 32;
        this.player.flipX = false;
    }

    if (this.cursors.up.isDown)
    {
        this.player.y -= 32;
    }
    else if (this.cursors.down.isDown)
    {
        this.player.y += 32;
    }
    // bounds check
    if (this.player.x < 0) {
        this.player.x = 0;
    }
    if (this.player.y < 0) {
        this.player.y = 0;
    }
    if (this.player.x > (width - 1) * 32) {
        this.player.x = (width - 1) * 32;
    }
    if (this.player.y > (height - 1) * 32) {
        this.player.y = (height - 1) * 32;
    }

    this.cameras.main.scrollX = this.player.x - 400;
    this.cameras.main.scrollY = this.player.y - 300;

    this.minimap.scrollX = Phaser.Math.Clamp(this.player.x - 80, 0, width * 32);
    this.minimap.scrollY = Phaser.Math.Clamp(this.player.y - 60, 0, height * 32);
}

 

Note the MapLoader & getflatdata just return an array numbers for the map which is working fine

Share this post


Link to post
Share on other sites

Not sure we've got a test that checks if you can zoom a tilemap. Could you boil it right down to just a simple piece of code that is literally just the map and a zoomed camera please? If that doesn't work you can open a GitHub issue and we'll sort it out asap.

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.