Jump to content

Googled, searched, can't constrain character movement


dmattox10
 Share

Recommended Posts

Using the isometric plugin for phaser, using code from the "Basic Character Movement" example, my player moves by default as an isometric player should (though not the preset amount of pixels). However, key combinations override the movement. UP + LEFT moves the character up, UP + RIGHT moves the player right, D + R moves the player down, and D + L moves the player left. How would I constrain the movement to isometric only? Even better still, how do I make the character "snap", in single movements, to the grid?

 

var width = window.innerWidth;
var height = window.innerHeight;
var player;
var game = new Phaser.Game(width, height, Phaser.AUTO, '', { preload: preload, create: create, update: update });

function preload() {
  game.load.spritesheet('player', 'assets/img/placeholder_man.png', 64, 128, 4); // Loads the spritesheet I created in TexturePacker
  game.plugins.add(new Phaser.Plugin.Isometric(game)); // Loads the Isometric plugin for Phaser
  game.time.advancedTiming = true; // Necessary to enable FPS counter later on
  game.physics.startSystem(Phaser.Plugin.Isometric.ISOARCADE); // Starts modifed physics for Isometric perspective
  game.iso.anchor.setTo(0.5, 0.2); // Offsets starting coordinates
}

function create() {
  //sprite = game.add.sprite(40, 100, 'player');

  //sprite.animations.add('turn');
  //sprite.animations.play('turn', 60, true);

  //cursors = game.input.keyboard.createCursorKeys();

        // group = game.add.isoSprite(200, 200, 0, 'player', 0); THIS DOES NOT WORK STOP GUESSING

        //group = game.add.group();

        //player = group.create(200, 200, 'player');
        player = game.add.isoSprite(200, 200, 0, 'player', 0); // DOES NOT WORK
        //player = group.create.isoSprite(200, 200, 0, 'player', 0); //DOES NOT WORK
        game.physics.enable(player, Phaser.Physics.ARCADE);
        //player.body.drag.set(300);
        //player.body.setSize(60, 25, 0, 42);
        //player.body.collideWorldBounds = true;
        //player.anchor.set(0.5);
        //game.physics.isoArcade.enable(player);
}

function update() {
  /*
  if (cursors.left.isDown) {
            player.body.velocity.x = -150;
            player.frame = 1;
        } else if (cursors.right.isDown) {
            player.body.velocity.x = 150;
            player.frame = 2;
        } else if (cursors.up.isDown) {
            player.body.velocity.y = -150;
            player.frame = 0;
        } else if (cursors.down.isDown) {
            player.body.velocity.y = 150;
            player.frame = 3;
        }
        */

        if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
    {
        player.isoX -= 100;
        player.frame = 1;
    }
    else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
    {
        player.isoX += 100;
        player.frame = 2;
    }

    if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
    {
        player.isoY -= 100;
        player.frame = 0;
    }
    else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
    {
        player.isoY += 100;
        player.frame = 3;
    }
        game.debug.text(game.time.fps || '--', 2, 14, "#a7aebe");

}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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