phaser4-rex-plugins
Version:
2 lines (1 loc) • 1.43 kB
JavaScript
var t,e;t=void 0,e=function(){const t=Phaser.Utils.Array.GetRandom,e=Phaser.Utils.Objects.GetValue;class s{constructor(t,e){this.data=[],this.setSource(t,e)}setSource(t,s){var i=t.canvas,a=e(s,"x",0),h=e(s,"y",0),o=e(s,"width",i.width-a),r=e(s,"height",i.height-h),n=i.getContext("2d",{willReadFrequently:!0}).getImageData(a,h,o,r).data,d=this.data;d.length=0;for(var f=0,l=n.length/4;f<l;f++)n[4*f+3]>0&&d.push(f);this.width=o,this.height=r;var u=e(s,"scaleX",t),c=e(s,"scaleY",void 0);this.setScale(u,c);var g=e(s,"offsetX",t),y=e(s,"offsetY",void 0);return this.setOffset(g,y),this}setOffset(t,e){if("number"!=typeof t){var s=t;t=-s.originX*s.displayWidth,e=-s.originY*s.displayHeight}return this.offsetX=t,this.offsetY=e,this}setScale(t,e){if("number"!=typeof t){var s=t;t=s.scaleX,e=s.scaleY}return void 0===e&&(e=t),this.scaleX=t,this.scaleY=e,this}getRandomPoint(e){if(void 0===e&&(e={}),this.data.length>0){var s=t(this.data),i=s%this.width,a=(s-i)/this.width;e.x=i*this.scaleX,e.y=a*this.scaleY}else e.x=0,e.y=0;return e.x+=this.offsetX,e.y+=this.offsetY,e}}class i extends Phaser.Plugins.BasePlugin{constructor(t){super(t)}start(){this.game.events.on("destroy",this.destroy,this)}add(t,e){return new s(t,e)}}return i},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexbitmapzoneplugin=e();