Jump to content

Phaser Isometric Player movement


NistorCristian
 Share

Recommended Posts

Hi,

I'm trying to make a player using the Isometric Plugin. My problem is that the player doesn't move. I'm sure it is not a problem in the movement code but it is somewhere else. Here is what I did:

var Start = function (game) { };Start.prototype =    {        preload: function () {            game.load.spritesheet('player', 'http://nistorcristian.com/game/img/player.png', 8, 25);            // game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;            game.time.advancedTiming = true;            // Add and enable the plug-in.            game.plugins.add(new Phaser.Plugin.Isometric(game));            // Start the IsoArcade physics system.            game.physics.startSystem(Phaser.Plugin.Isometric.ISOARCADE);            game.world.setBounds(0, 0, 3000, 3000);            game.iso.anchor.setTo(0.5, 0.2);            },        create: function () {            // Create a group for our tiles, so we can use Group.sort            isoGroup = game.add.group();            isoMarginGroup = game.add.group();            // Set the global gravity for IsoArcade.            game.physics.isoArcade.gravity.setTo(0, 0, -500);            player = new Player(this.game, 1390, 1450);            game.add.existing(player);            game.camera.follow(player);        },        update: function () {        }    };    var Player = function (game, x, y) {        // player = game.add.isoSprite(390, 450, 0, 'player', 2);        Phaser.Sprite.call(this, game, x, y, 'player');        this.tint = 0x86bfda;        this.anchor.set(0.5);        game.physics.isoArcade.enable(this);        this.body.collideWorldBounds = true;        this.animations.add('up', [3], 12, true);        this.animations.add('down', [0], 12, true);        this.animations.add('left', [2], 12, true);        this.animations.add('right', [1], 12, true);    };    Player.prototype = Object.create(Phaser.Sprite.prototype);    Player.prototype.constructor = Player;    Player.prototype.update = function() {        this.cursors = game.input.keyboard.createCursorKeys();        this.game.input.keyboard.addKeyCapture([            Phaser.Keyboard.LEFT,            Phaser.Keyboard.RIGHT,            Phaser.Keyboard.UP,            Phaser.Keyboard.DOWN,            Phaser.Keyboard.SPACEBAR        ]);        // this.angle += this.rotateSpeed;        var player = this;        if (this.cursors.up.isDown) {            if (facing != 'up'){                player.animations.play('up');                facing = 'up';            }             player.body.velocity.y = -speed;        }        else if (this.cursors.down.isDown) {            if (facing != 'down'){                player.animations.play('down');                facing = 'down';            }             player.body.velocity.y = speed;        }        else {            player.body.velocity.y = 0;        }        if (this.cursors.left.isDown) {            if (facing != 'left'){                player.animations.play('left');                facing = 'left';            }            player.body.velocity.x = -speed;        }        else if (this.cursors.right.isDown) {            if (facing != 'right'){                player.animations.play('right');                facing = 'right';            }               player.body.velocity.x = speed;        }        else {            player.body.velocity.x = 0;        }    };

The animation is changing but the player doesn't move. I don't think I add the player correctly. 

 

Thank you

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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