Phaser.js world学习案例3-world-wrap

原demo地址http://www.phaser.io/examples/v2/world/world-wrap
效果图这里写图片描述

Phaser.js world学习案例1-固定相机显示
Phaser.js world学习案例2-move around world

var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example',
    { preload: preload, create: create, update: update, render: render });
function preload() {
    game.load.image('backdrop', '../assets/pics/remember-me.jpg');
    game.load.image('card', '../assets/sprites/mana_card.png');
}
var card;
var cursors;
function create() {
    game.world.setBounds(0, 0, 1920, 1200);
    game.add.sprite(0, 0, 'backdrop');
    card = game.add.sprite(200, 200, 'card');
    //设置相机跟随card精灵
    game.camera.follow(card);
    cursors = game.input.keyboard.createCursorKeys();
}
function update() {
    if (cursors.left.isDown)
        card.x -= 4;
    else if (cursors.right.isDown)
        card.x += 4;
    if (cursors.up.isDown)
        card.y -= 4;
    else if (cursors.down.isDown)
        card.y += 4;
    //设置card精灵在世界边界里可以自适应位置,即从上边出去会从下边进来
    //第二个参数  包裹精灵的内边距
    game.world.wrap(card, 0, true);
}

function render() {
    game.debug.cameraInfo(game.camera, 500, 32);
    game.debug.spriteCoords(card, 32, 32);
}

猜你喜欢

转载自blog.csdn.net/cre2017/article/details/81416095