class Example extends Phaser.Scene { preload () { this.load.setBaseURL('https://cdn.phaserfiles.com/v385'); this.load.image('akira', 'assets/pics/akira.jpg'); } create () { this.add.image(400, 350, 'akira').setScale(0.7); this.createSpeechBubble(20, 20, 320, 160, '“Twin ceramic rotor drives on each wheel! And these look like computer controlled anti-lock brakes! Wow, 200 horses at 12,000 rpm!”'); this.createSpeechBubble(370, 120, 400, 180, '“Kaneda, you\'ve always been a pain in the ass, you know. You\'ve been telling me what to do since we were kids. You always treat me like a kid. You always show up and start bossing me around, and don\'t you deny it!”'); this.createSpeechBubble(70, 400, 250, 100, '“And now you\'re a boss, too... of this pile of rubble.”'); } createSpeechBubble (x, y, width, height, quote) { const bubbleWidth = width; const bubbleHeight = height; const bubblePadding = 10; const arrowHeight = bubbleHeight / 4; const bubble = this.add.graphics({ x: x, y: y }); // Bubble shadow bubble.fillStyle(0x222222, 0.5); bubble.fillRoundedRect(6, 6, bubbleWidth, bubbleHeight, 16); // Bubble color bubble.fillStyle(0xffffff, 1); // Bubble outline line style bubble.lineStyle(4, 0x565656, 1); // Bubble shape and outline bubble.strokeRoundedRect(0, 0, bubbleWidth, bubbleHeight, 16); bubble.fillRoundedRect(0, 0, bubbleWidth, bubbleHeight, 16); // Calculate arrow coordinates const point1X = Math.floor(bubbleWidth / 7); const point1Y = bubbleHeight; const point2X = Math.floor((bubbleWidth / 7) * 2); const point2Y = bubbleHeight; const point3X = Math.floor(bubbleWidth / 7); const point3Y = Math.floor(bubbleHeight + arrowHeight); // Bubble arrow shadow bubble.lineStyle(4, 0x222222, 0.5); bubble.lineBetween(point2X - 1, point2Y + 6, point3X + 2, point3Y); // Bubble arrow fill bubble.fillTriangle(point1X, point1Y, point2X, point2Y, point3X, point3Y); bubble.lineStyle(2, 0x565656, 1); bubble.lineBetween(point2X, point2Y, point3X, point3Y); bubble.lineBetween(point1X, point1Y, point3X, point3Y); const content = this.add.text(0, 0, quote, { fontFamily: 'Arial', fontSize: 20, color: '#000000', align: 'center', wordWrap: { width: bubbleWidth - (bubblePadding * 2) } }); const b = content.getBounds(); content.setPosition(bubble.x + (bubbleWidth / 2) - (b.width / 2), bubble.y + (bubbleHeight / 2) - (b.height / 2)); } } const config = { type: Phaser.AUTO, width: 800, height: 600, parent: 'phaser-example', scene: Example }; const game = new Phaser.Game(config);
Scan to open on your mobile device
class Example extends Phaser.Scene { preload () { this.load.setBaseURL('https://cdn.phaserfiles.com/v385'); this.load.image('akira', 'assets/pics/akira.jpg'); } create () { this.add.image(400, 350, 'akira').setScale(0.7); this.createSpeechBubble(20, 20, 320, 160, '“Twin ceramic rotor drives on each wheel! And these look like computer controlled anti-lock brakes! Wow, 200 horses at 12,000 rpm!”'); this.createSpeechBubble(370, 120, 400, 180, '“Kaneda, you\'ve always been a pain in the ass, you know. You\'ve been telling me what to do since we were kids. You always treat me like a kid. You always show up and start bossing me around, and don\'t you deny it!”'); this.createSpeechBubble(70, 400, 250, 100, '“And now you\'re a boss, too... of this pile of rubble.”'); } createSpeechBubble (x, y, width, height, quote) { const bubbleWidth = width; const bubbleHeight = height; const bubblePadding = 10; const arrowHeight = bubbleHeight / 4; const bubble = this.add.graphics({ x: x, y: y }); // Bubble shadow bubble.fillStyle(0x222222, 0.5); bubble.fillRoundedRect(6, 6, bubbleWidth, bubbleHeight, 16); // Bubble color bubble.fillStyle(0xffffff, 1); // Bubble outline line style bubble.lineStyle(4, 0x565656, 1); // Bubble shape and outline bubble.strokeRoundedRect(0, 0, bubbleWidth, bubbleHeight, 16); bubble.fillRoundedRect(0, 0, bubbleWidth, bubbleHeight, 16); // Calculate arrow coordinates const point1X = Math.floor(bubbleWidth / 7); const point1Y = bubbleHeight; const point2X = Math.floor((bubbleWidth / 7) * 2); const point2Y = bubbleHeight; const point3X = Math.floor(bubbleWidth / 7); const point3Y = Math.floor(bubbleHeight + arrowHeight); // Bubble arrow shadow bubble.lineStyle(4, 0x222222, 0.5); bubble.lineBetween(point2X - 1, point2Y + 6, point3X + 2, point3Y); // Bubble arrow fill bubble.fillTriangle(point1X, point1Y, point2X, point2Y, point3X, point3Y); bubble.lineStyle(2, 0x565656, 1); bubble.lineBetween(point2X, point2Y, point3X, point3Y); bubble.lineBetween(point1X, point1Y, point3X, point3Y); const content = this.add.text(0, 0, quote, { fontFamily: 'Arial', fontSize: 20, color: '#000000', align: 'center', wordWrap: { width: bubbleWidth - (bubblePadding * 2) } }); const b = content.getBounds(); content.setPosition(bubble.x + (bubbleWidth / 2) - (b.width / 2), bubble.y + (bubbleHeight / 2) - (b.height / 2)); } } const config = { type: Phaser.AUTO, width: 800, height: 600, parent: 'phaser-example', scene: Example }; const game = new Phaser.Game(config);