douglas

Speed and Frame Rate

Recommended Posts

I am trying to fix the speed and framerate for Link if someone have any idea for doing computations, speed = function(framerate) for example

Here is the code : http://codepen.io/featuresmega/pen/ALKLEj

var game;
var map;
var layer, layer1, layer2;
var player;
var cursors;

game = new Phaser.Game(800, 600, Phaser.CANVAS, 'Zelda Mysteries of PhaserIO', { preload: preload, create: create, update: update, render: render });

function preload() {

    game.load.tilemap('zelda', 'http://crossorigin.me/http://asciimulation.link/assets/tiles/zelda.json', null, Phaser.Tilemap.TILED_JSON);
    game.load.image('tiles', 'http://crossorigin.me/http://asciimulation.link/assets/tiles/light_world.tiles.png');
    game.load.spritesheet('link', 'http://crossorigin.me/http://asciimulation.link/assets/sprites/walking.tunic.png', 24, 32, 55);
}

function create() {
//World
    map = game.add.tilemap('zelda');
    map.addTilesetImage('light_world.tiles', 'tiles');
    currentTile = map.getTile(2, 3);

    layer = map.createLayer('Calque de Tile 1');
    layer = map.createLayer('Calque 2');
//Player

    player = game.add.sprite(50, 150, 'link');
    player.scale.set(2);
    player.smoothed = false;

    player.animations.add('right', [0, 1, 2, 3, 4, 5, 6, 7], 20, false);
    player.animations.add('up', [12, 13, 14, 15, 16, 17, 18], 8, false);
    player.animations.add('left', [33, 34, 35, 36, 37, 38, 39, 40], 8, false);
    player.animations.add('down', [44, 45, 46, 47, 48, 49, 50, 51], 8, false);

    game.physics.enable(player, Phaser.Physics.ARCADE);
    game.camera.follow(player);

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

}

function update() {
    player.body.velocity.x = 0;
    player.body.velocity.y = 0;

    var speed = 200;

    if (cursors.right.isDown)
    {
        game.camera.x += 4;
        player.body.velocity.x = +speed;
        player.animations.play('right');
    }

    else if (cursors.up.isDown)
    {
        game.camera.y -= 4;
        player.body.velocity.y = -speed;
        player.animations.play('up');
    }

    else if (cursors.left.isDown)
    {
        game.camera.x -= 4;
        player.body.velocity.x = -speed;
        player.animations.play('left');
    }

    else if (cursors.down.isDown)
    {
        game.camera.y += 4;
        player.body.velocity.y = +speed;
        player.animations.play('down');
    } else {

        player.animations.stop();
    }

}

function render() {

    game.debug.spriteInfo(player, 20, 32);

}

 

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.