-
Notifications
You must be signed in to change notification settings - Fork 6
/
floatingText.min.js
1 lines (1 loc) · 5.26 KB
/
floatingText.min.js
1
var FloatingText=function(a,b){function g(e){var f=b.text||"",g=b.textOptions||{fontSize:12,fill:"#ffffff",stroke:"#1e1e1e",strokeThickness:1,wordWrap:!0,wordWrapWidth:200},i=b.sprite||null,j=b.spriteAnimationName||"",k=b.spriteAnimationFrames||[],l=b.spriteAnimationFrameRate||24,m=b.spriteAnimationRepeat||!0,o=(b.playAnimationOnStart||!0,b.spriteAnchor||.5),p=b.x||"auto",q=b.y||"auto",r=b.rotation||!1,s=b.parentObj||null,v=(b.width||"auto",b.height||"auto",b.hasBackground||!1),w=b.backgroundColor||0,x=b.animation||"explode",y=b.distance||40,z=b.easing||Phaser.Easing.Quintic.Out,A=b.timeToLive||600,B=b.fixedToCamera||!1,C=b.align||"center",D=b.customPath||[];null===i?c=a.add.text(0,0,f,g):(c=a.add.sprite(i.x,i.y,i.key,k[0]),c.anchor.setTo(o),c.animations.add(j,k,l,m,!0)),r!==!1&&(c.angle=r),null!==s&&void 0!==s?("auto"===p?0===s.anchor?c.x=s.x+s.width/2-c.width/2:c.x=s.x-c.width/2:c.x=p,"auto"===q?0===s.anchor?c.y=s.y+s.height/2-c.height/2:c.y=s.y-c.height/2:c.y=q):"center"===C?null!==i?(c.x=p-c.width*o/2,c.y=q-c.height*o/2):(c.x=p-c.width/2,c.y=q-c.height/2):"left"===C?(c.x=p,c.y=q):"right"===C?(c.x=p+c.width,c.y=q+c.height):"none"===C&&(c.x=p,c.y=q);var E;return v===!0?(E=a.add.graphics(c.width+10,c.height),E.beginFill(w,1),d.width=c.width+5,d.height=c.width+5,E.drawRoundedRect(0,0,c.width+10,c.height,6),E.endFill(),d.add(E)):(d.width=c.width,d.height=c.height),B===!0&&(d.fixedToCamera=!0),d.x=c.x,d.y=c.y,c.x=0,c.y=0,void 0!==E&&(E.x=-5,E.y=0),c._animation=x,c._easing=z,c._timeToLive=A,c._distance=y,c._customPath=D,c._spriteAnimationName=j,c._sprite=i,d.add(c),d.visible=!1,e===!0?d:void h()}function h(){var b=c._animation;if(d.visible=!0,null!==c._sprite&&c.animations.play(c._spriteAnimationName),"physics"===b){var e=d.x,f=d.y,g=a.rnd.integerInRange(0,10);if(g>5)var h=d.x+25,i=d.y-50,k=d.x+50,l=d.y-25,m=d.x+100,n=d.y+50;else var h=d.x-25,i=d.y-50,k=d.x-50,l=d.y-25,m=d.x-100,n=d.y+50;var o=a.add.tween(d).to({x:[e,h,k,m],y:[f,i,l,n]},c.timeToLive,Phaser.Easing.Circular.Out,!0).interpolation(function(a,b){return Phaser.Math.bezierInterpolation(a,b)});o.onComplete.addOnce(function(){var a=j(this,"alpha",{alpha:0},250,0);a.onComplete.addOnce(function(){this.destroy()},this)},d)}else if("custom"===b){for(var p=[],q=[],r=0;r<c._customPath.length;r++)p.push(c._customPath[r].x),p.push(c._customPath[r].y);var o=a.add.tween(d).to({x:p,y:q},c.timeToLive,Phaser.Easing.Circular.Out,!0).interpolation(function(a,b){return Phaser.Math.bezierInterpolation(a,b)});o.onComplete.addOnce(function(){var a=j(this,"alpha",{alpha:0},250,0);a.onComplete.addOnce(function(){this.destroy()},this)},d)}else if("explode"===b){d.pivot.setTo(.5,.5);var s=d.children[d.children.length-1],o=j(s,"size",{fontSize:2*s.fontSize},250,0,Phaser.Easing.Back.Out),t=2*s.width-s.width,u=2*s.height-s.height;j(d.position,"position",{x:d.position.x-t/2,y:d.position.y-u/2},250,0,Phaser.Easing.Back.Out),o.onComplete.addOnce(function(){var a=j(this,"alpha",{alpha:0},250,c._timeToLive);a.onComplete.addOnce(function(){this.destroy()},this)},d)}else if("smoke"===b){for(var e=d.x,f=d.y,g=a.rnd.integerInRange(0,10),p=[],q=[],v=0,r=0;r<12;r++)v<3&&v>0?(p.push(e+10*Math.abs(v)),q.push(f-c._distance/12*r),v+=1):3===v?(v=0,p.push(e-10*Math.abs(v)),q.push(f-c._distance/12*r),v-=1):v===-3?(v=0,p.push(e-10*Math.abs(v)),q.push(f-c._distance/12*r),v+=1):v>-3&&(p.push(e-10*Math.abs(v)),q.push(f-c._distance/12*r),v-=1);var o=a.add.tween(d).to({x:p,y:q},c.timeToLive,Phaser.Easing.Circular.Out,!0).interpolation(function(a,b){return Phaser.Math.bezierInterpolation(a,b)});o.onComplete.addOnce(function(){var a=j(this,"alpha",{alpha:0},250,0);a.onComplete.addOnce(function(){this.destroy()},this)},d)}else if("up"===b){var o=j(d,"y",{y:d.y-c._distance},400,100,c._easing);o.onComplete.addOnce(function(){reg.floatingGroup=d;var a=j(d,"alpha",{alpha:0},150,c._timeToLive);a.onComplete.addOnce(function(){this.removeAll(!0),this.destroy()},this)},d)}else if("down"===b){var o=j(d,"y",{y:d.y+c._distance},400,100,c._easing);o.onComplete.addOnce(function(){var a=j(this,"alpha",{alpha:0},250,c._timeToLive);a.onComplete.addOnce(function(){this.destroy()},this)},d)}else if("left"===b){var o=j(d,"y",{y:d.x-c._distance},400,100,c._easing);o.onComplete.addOnce(function(){var a=j(this,"alpha",{alpha:0},250,c._timeToLive);a.onComplete.addOnce(function(){this.destroy()},this)},d)}else if("right"===b){var o=j(d,"y",{y:d+c._distance},400,100,c._easing);o.onComplete.addOnce(function(){var a=j(this,"alpha",{alpha:0},250,c._timeToLive);a.onComplete.addOnce(function(){this.destroy()},this)},d)}else if("fade"===b){d.alpha=0;var o=j(d,"alpha",{alpha:1},250,50,c._easing);o.onComplete.addOnce(function(){var a=j(this,"alpha",{alpha:0},350,c._timeToLive);a.onComplete.addOnce(function(){this.destroy()},this)},d)}}function i(){var c=b.numOfItems||50;e=a.add.group();for(var d=0;d<c;d++)e.add(g(!0))}function j(b,c,d,e,f,g,h,i,j){f=f||{},g=g||Phaser.Easing.Linear.None,h=h||!1,i=i||0;var k=a.add.tween(b).to(d,e,g,!0,f,i,h);return k.reverse=j||!1,k}var e,c={},d=a.add.group();[Phaser.Easing.Cubic.InOut,Phaser.Easing.Sinusoidal.In,Phaser.Easing.Quadratic.InOut,Phaser.Easing.Quartic.Out,Phaser.Easing.Linear,Phaser.Easing.Cubic.In,Phaser.Easing.Quintic.Out,Phaser.Easing.Quintic.InOut];return void 0!==b.numOfItems?i():g(),{showFloatingText:function(){d.visible=!0},hideFloatingText:function(){d.visible=!1}}};