1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'parentId', { preload: preload, create: create, update: update, render : render });
game.load.image('phaser', 'assets/phaser.png');
game.load.spritesheet('player', 'assets/player.png', 32, 48);
game.world.setBounds(-1000, -1000, 2000, 2000);
game.physics.startSystem(Phaser.Physics.ARCADE);
game.physics.arcade.enable(player);
game.physics.arcade.collide(player, platforms);
platforms = game.add.group();
ground = platforms.create(400, 400, 'ground');
ground.body.immovable = true;
player.body.collideWorldBounds = true;
player.animations.add('left', [0, 1, 2, 3], 10, true);
player.animations.play('left');
player.body.velocity.x = 10;
player.body.gravity.y = 10;
logo = game.add.sprite(100, 100, 'phaser');
game.world.randomX game.world.randomY
game.add.text(0, 0, 'this text scrolls\nwith the background', { font: '32px Arial', fill: '#f26c4f', align: 'center' })
logo.fixedToCamera = true; logo.cameraOffset.setTo(100, 100);
game.add.tween(logo.cameraOffset).to( { y: 400 }, 2000, Phaser.Easing.Back.InOut, true, 0, 2000, true );
cursors = game.input.keyboard.createCursorKeys(); if (cursors.up.isDown) { game.camera.y -= 4; }
logo.events.onInputDown.add(func, this);
game.camera.follow(logo);
game.world.wrap(logo, 0, true);
|