|
| 1 | + |
| 2 | +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); |
| 3 | + |
| 4 | +function preload() { |
| 5 | + |
| 6 | + game.load.image('backdrop', 'assets/pics/remember-me.jpg'); |
| 7 | + game.load.image('mushroom', 'assets/sprites/mushroom2.png'); |
| 8 | + game.load.image('coke', 'assets/sprites/cokecan.png'); |
| 9 | + game.load.bitmapFont('desyrel', 'assets/fonts/bitmapFonts/desyrel.png', 'assets/fonts/bitmapFonts/desyrel.xml', null, 0, -32); |
| 10 | + |
| 11 | +} |
| 12 | + |
| 13 | +var cursors; |
| 14 | +var mushroom; |
| 15 | + |
| 16 | +function create() { |
| 17 | + |
| 18 | + game.world.setBounds(0, 0, 1920, 1200); |
| 19 | + game.add.image(0, 0, 'backdrop'); |
| 20 | + |
| 21 | + mushroom = game.add.sprite(400, 400, 'mushroom'); |
| 22 | + |
| 23 | + // Test Fixing an Image to the Camera |
| 24 | + var fixie = game.add.image(100, 100, 'coke'); |
| 25 | + fixie.fixedToCamera = true; |
| 26 | + |
| 27 | + // And tween it |
| 28 | + game.add.tween(fixie.cameraOffset).to({ y: 500 }, 2000, Phaser.Easing.Bounce.Out, true, 0, 1000, true); |
| 29 | + |
| 30 | + // Test Fixing a Sprite to the Camera |
| 31 | + var fixie2 = game.add.sprite(600, 100, 'coke'); |
| 32 | + fixie2.fixedToCamera = true; |
| 33 | + fixie2.inputEnabled = true; |
| 34 | + fixie2.events.onInputDown.add(clicked, this); |
| 35 | + |
| 36 | + // Test Fixing a Text to the Camera |
| 37 | + var text = game.add.text(300, 32, '-phaser-'); |
| 38 | + text.fixedToCamera = true; |
| 39 | + |
| 40 | + // Test fixing a BitmapText to the Camera |
| 41 | + var text2 = game.add.bitmapText(200, 500, 'desyrel', 'camera fixies', 32); |
| 42 | + text2.fixedToCamera = true; |
| 43 | + |
| 44 | + // Test fixing a Graphics object to the Camera |
| 45 | + var graphics = game.add.graphics(0, 0); |
| 46 | + graphics.fixedToCamera = true; |
| 47 | + graphics.beginFill(0xFF3300); |
| 48 | + graphics.lineStyle(2, 0x0000FF, 1); |
| 49 | + graphics.drawRect(50, 250, 100, 100); |
| 50 | + |
| 51 | + // Button! do mouse events still work then? |
| 52 | + |
| 53 | + game.camera.scale.set(2); |
| 54 | + |
| 55 | + game.camera.follow(mushroom); |
| 56 | + |
| 57 | + cursors = game.input.keyboard.createCursorKeys(); |
| 58 | + |
| 59 | +} |
| 60 | + |
| 61 | +function clicked() { |
| 62 | + |
| 63 | + console.log('boom'); |
| 64 | + |
| 65 | +} |
| 66 | + |
| 67 | +function update() { |
| 68 | + |
| 69 | + if (cursors.left.isDown) |
| 70 | + { |
| 71 | + mushroom.x -= 8; |
| 72 | + } |
| 73 | + else if (cursors.right.isDown) |
| 74 | + { |
| 75 | + mushroom.x += 8; |
| 76 | + } |
| 77 | + |
| 78 | + if (cursors.up.isDown) |
| 79 | + { |
| 80 | + mushroom.y -= 8; |
| 81 | + } |
| 82 | + else if (cursors.down.isDown) |
| 83 | + { |
| 84 | + mushroom.y += 8; |
| 85 | + } |
| 86 | + |
| 87 | +} |
| 88 | + |
| 89 | +function render() { |
| 90 | + |
| 91 | + |
| 92 | +} |
0 commit comments