function NextChocoballBubble(x, y) { this.posY = y; this.bubble = this.makeBubbleSprite(x, y); } NextChocoballBubble.prototype.makeBubbleSprite = function(x, y) { var graphics = new Phaser.Graphics(game, 0, 0); var triangleStartX = 0; var triangleStartY = NextChocoballBubble.RADIUS / 7 * 4; var triangleHalfWidth = NextChocoballBubble.TRIANGLE_WIDTH / 2; // tail outline graphics.lineStyle(NextChocoballBubble.STROKE_WIDTH, NextChocoballBubble.COLOR_BUBBLE_STROKE); graphics.beginFill(NextChocoballBubble.COLOR_BUBBLE_FILL); graphics.moveTo(triangleStartX, triangleStartY); graphics.lineTo(triangleStartX + triangleHalfWidth, triangleStartY - NextChocoballBubble.TRIANGLE_HEIGHT); graphics.lineTo(triangleStartX - triangleHalfWidth, triangleStartY - NextChocoballBubble.TRIANGLE_HEIGHT); graphics.lineTo(triangleStartX, triangleStartY); graphics.endFill(); // circle graphics.lineStyle(NextChocoballBubble.STROKE_WIDTH / 2, NextChocoballBubble.COLOR_BUBBLE_STROKE); graphics.beginFill(NextChocoballBubble.COLOR_BUBBLE_FILL); graphics.drawCircle(0, 0, NextChocoballBubble.RADIUS); graphics.endFill(); // tail body graphics.lineStyle(0); graphics.beginFill(NextChocoballBubble.COLOR_BUBBLE_FILL); graphics.moveTo(triangleStartX, triangleStartY); graphics.lineTo(triangleStartX + triangleHalfWidth, triangleStartY - NextChocoballBubble.TRIANGLE_HEIGHT); graphics.lineTo(triangleStartX - triangleHalfWidth, triangleStartY - NextChocoballBubble.TRIANGLE_HEIGHT); graphics.lineTo(triangleStartX, triangleStartY); graphics.endFill(); texture = graphics.generateTexture(); sprite = game.add.sprite(x, y, texture); sprite.anchor.set(0.5); return sprite; } NextChocoballBubble.prototype.addChild = function(chocoball) { this.bubble.addChild(chocoball); chocoball.y -= NextChocoballBubble.TRIANGLE_HEIGHT / 9 * 2; } NextChocoballBubble.prototype.animateNextHint = function() { this.bubble.y = this.posY + NextChocoballBubble.ANIMATION_HEIGHT; var tween = game.add.tween(this.bubble); tween.to({y:this.posY}, 500, Phaser.Easing.Quadratic.Out, true, 0); tween.onComplete.add(this.animateReset, this); tween.start(); } NextChocoballBubble.prototype.animateReset = function() { this.bubble.y = this.posY; } NextChocoballBubble.RADIUS = 110; NextChocoballBubble.TRIANGLE_HEIGHT = 40; NextChocoballBubble.TRIANGLE_WIDTH = 40; NextChocoballBubble.STROKE_WIDTH = 10; NextChocoballBubble.OFFSET_Y = 240; NextChocoballBubble.ANIMATION_HEIGHT = 20; NextChocoballBubble.COLOR_BUBBLE_FILL = 0xFFEEEE; NextChocoballBubble.COLOR_BUBBLE_STROKE = 0x331122;