|
| 1 | + |
| 2 | +var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { create: create }); |
| 3 | + |
| 4 | +var text = null; |
| 5 | +var textReflect = null; |
| 6 | + |
| 7 | +function create() { |
| 8 | + |
| 9 | + game.stage.backgroundColor = 0x3b0760; |
| 10 | + |
| 11 | + text = game.add.text(game.world.centerX, game.world.centerY, "- PHASER -"); |
| 12 | + |
| 13 | + // Centers the text |
| 14 | + text.anchor.set(0.5); |
| 15 | + text.align = 'center'; |
| 16 | + |
| 17 | + // Our font + size |
| 18 | + text.font = 'Arial'; |
| 19 | + text.fontWeight = 'bold'; |
| 20 | + text.fontSize = 70; |
| 21 | + text.fill = '#ffffff'; |
| 22 | + |
| 23 | + // Here we create our fake reflection :) |
| 24 | + // It's just another Text object, with an alpha gradient and flipped vertically |
| 25 | + |
| 26 | + textReflect = game.add.text(game.world.centerX, game.world.centerY + 50, "- PHASER -"); |
| 27 | + |
| 28 | + // Centers the text |
| 29 | + textReflect.anchor.set(0.5); |
| 30 | + textReflect.align = 'center'; |
| 31 | + textReflect.scale.y = -1; |
| 32 | + |
| 33 | + // Our font + size |
| 34 | + textReflect.font = 'Arial'; |
| 35 | + textReflect.fontWeight = 'bold'; |
| 36 | + textReflect.fontSize = 70; |
| 37 | + |
| 38 | + // Here we create a linear gradient on the Text context. |
| 39 | + // This uses the exact same method of creating a gradient as you do on a normal Canvas context. |
| 40 | + var grd = textReflect.context.createLinearGradient(0, 0, 0, text.canvas.height); |
| 41 | + |
| 42 | + // Add in 2 color stops |
| 43 | + grd.addColorStop(0, 'rgba(255,255,255,0)'); |
| 44 | + grd.addColorStop(1, 'rgba(255,255,255,0.08)'); |
| 45 | + |
| 46 | + // And apply to the Text |
| 47 | + textReflect.fill = grd; |
| 48 | + |
| 49 | +} |
0 commit comments