相机 Camera
1. 镜头跟随 7.完整代码: var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.image('background','assets/tests/debug-grid-1920x1920.png');
game.load.image('player','assets/sprites/phaser-dude.png');
}
var player;
var cursors;
function create() {
game.add.tileSprite(0, 0, 1920, 1920, 'background');
game.world.setBounds(0, 0, 1920, 1920);
game.physics.startSystem(Phaser.Physics.P2JS);
player = game.add.sprite(game.world.centerX, game.world.centerY, 'player');
game.physics.p2.enable(player);
cursors = game.input.keyboard.createCursorKeys();
game.camera.follow(player);
}
function update() {
player.body.setZeroVelocity();
if (cursors.up.isDown)
{
player.body.moveUp(300)
}
else if (cursors.down.isDown)
{
player.body.moveDown(300);
}
if (cursors.left.isDown)
{
player.body.velocity.x = -300;
}
else if (cursors.right.isDown)
{
player.body.moveRight(300);
}
}
function render() {
game.debug.cameraInfo(game.camera, 32, 32);
game.debug.spriteCoords(player, 32, 500);
}
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); function preload() { game.load.image('background','assets/tests/debug-grid-1920x1920.png'); game.load.image('player','assets/sprites/phaser-dude.png'); } var player; var cursors; function create() { game.add.tileSprite(0, 0, 1920, 1920, 'background'); game.world.setBounds(0, 0, 1920, 1920); game.physics.startSystem(Phaser.Physics.P2JS); player = game.add.sprite(game.world.centerX, game.world.centerY, 'player'); game.physics.p2.enable(player); cursors = game.input.keyboard.createCursorKeys(); game.camera.follow(player); } function update() { player.body.setZeroVelocity(); if (cursors.up.isDown) { player.body.moveUp(300) } else if (cursors.down.isDown) { player.body.moveDown(300); } if (cursors.left.isDown) { player.body.velocity.x = -300; } else if (cursors.right.isDown) { player.body.moveRight(300); } } function render() { game.debug.cameraInfo(game.camera, 32, 32); game.debug.spriteCoords(player, 32, 500); }
查看更多关于phaser教程之相机camera的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did31424