Phaser.jsワールドスタディケース3-ワールドラップ



Phaser Js World Study Case 3 World Wrap

元のデモアドレス http://www.phaser.io/examples/v2/world/world-wrap
レンダリング

Phaser.jsワールドスタディケース1-固定カメラディスプレイ
Phaser.jsワールドスタディケース2-世界中を移動



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') //Set the camera to follow the card sprite 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 //Set the card sprite to adapt to the position in the world boundary, that is, if you go out from the top, you will come in from the bottom //The second parameter wraps the inner margin of the sprite game.world.wrap(card, 0, true) } function render() { game.debug.cameraInfo(game.camera, 500, 32) game.debug.spriteCoords(card, 32, 32) }