@smoud/tiny
Version:
Fast and tiny JavaScript library for HTML5 game and playable ads creation.
1 lines • 5.52 kB
JavaScript
!function(){var t={548:function(){Tiny.SpriteBatch&&(Tiny.SpriteBatch.prototype.renderTilingSprite=function(t){var e=t.tilingTexture;this.currentBatchSize>=this.size&&(this.flush(),this.currentBaseTexture=e.base),t._uvs||(t._uvs=new Tiny.TextureUvs);var i=t._uvs;t.tilePosition.x%=e.base.width*t.tileScaleOffset.x,t.tilePosition.y%=e.base.height*t.tileScaleOffset.y;var s=t.tilePosition.x/(e.base.width*t.tileScaleOffset.x),r=t.tilePosition.y/(e.base.height*t.tileScaleOffset.y),h=t.width/e.base.width/(t.tileScale.x*t.tileScaleOffset.x),n=t.height/e.base.height/(t.tileScale.y*t.tileScaleOffset.y);i.x0=0-s,i.y0=0-r,i.x1=1*h-s,i.y1=0-r,i.x2=1*h-s,i.y2=1*n-r,i.x3=0-s,i.y3=1*n-r;var a=t.tint.int,l=(a>>16)+(65280&a)+((255&a)<<16)+(255*t.alpha<<24),o=this.positions,c=this.colors,u=t.width,x=t.height,g=t.anchor.x,f=t.anchor.y,d=u*(1-g),p=u*-g,T=x*(1-f),y=x*-f,w=4*this.currentBatchSize*this.vertSize,_=e.base.resolution,b=t.worldTransform,v=b.a/_,S=b.b/_,m=b.c/_,B=b.d/_,M=b.tx,k=b.ty;o[w++]=v*p+m*y+M,o[w++]=B*y+S*p+k,o[w++]=i.x0,o[w++]=i.y0,c[w++]=l,o[w++]=v*d+m*y+M,o[w++]=B*y+S*d+k,o[w++]=i.x1,o[w++]=i.y1,c[w++]=l,o[w++]=v*d+m*T+M,o[w++]=B*T+S*d+k,o[w++]=i.x2,o[w++]=i.y2,c[w++]=l,o[w++]=v*p+m*T+M,o[w++]=B*T+S*p+k,o[w++]=i.x3,o[w++]=i.y3,c[w++]=l,this.sprites[this.currentBatchSize++]=t})}},e={};function i(s){var r=e[s];if(void 0!==r)return r.exports;var h=e[s]={exports:{}};return t[s](h,h.exports,i),h.exports}!function(){"use strict";var t=function(t,e,i,s){Tiny.Sprite.call(this,t,e),this._width=i||100,this._height=s||100,this.tileScale=new Tiny.Vec2(1,1),this.tileScaleOffset=new Tiny.Vec2(1,1),this.tilePosition=new Tiny.Vec2(0,0)};(t.prototype=Object.create(Tiny.Sprite.prototype)).constructor=t,Object.defineProperty(t.prototype,'width',{get:function(){return this._width},set:function(t){this._width=t}}),Object.defineProperty(t.prototype,'height',{get:function(){return this._height},set:function(t){this._height=t}}),Object.assign(t.prototype,{setTexture:function(t,e){var i=Tiny.Sprite.prototype.setTexture.call(this,t,e);this.refreshTexture=i},render:function(t){if(!1!==this.visible&&0!==this.alpha){var e,i;for(this._mask&&(t.spriteBatch.stop(),t.maskManager.pushMask(this.mask,t),t.spriteBatch.start()),this._filters&&(t.spriteBatch.flush(),t.filterManager.pushFilter(this._filterBlock)),!this.tilingTexture||this.refreshTexture?(this.generateTilingTexture(!0),this.tilingTexture&&this.tilingTexture.needsUpdate&&(t.renderer.updateTexture(this.tilingTexture.base),this.tilingTexture.needsUpdate=!1)):t.spriteBatch.renderTilingSprite(this),e=0,i=this.children.length;e<i;e++)this.children[e].render(t);t.spriteBatch.stop(),this._filters&&t.filterManager.popFilter(),this._mask&&t.maskManager.popMask(this._mask,t),t.spriteBatch.start()}},renderCanvas:function(t){if(!1!==this.visible&&0!==this.alpha){var e=t.context;this._mask&&t.maskManager.pushMask(this._mask,t),e.globalAlpha=this.worldAlpha;var i,s,r=this.worldTransform,h=t.resolution;if(e.setTransform(r.a*h,r.b*h,r.c*h,r.d*h,r.tx*h,r.ty*h),!this.__tilePattern||this.refreshTexture){if(this.generateTilingTexture(!1),!this.tilingTexture)return;this.__tilePattern=e.createPattern(this.tilingTexture.base.source,'repeat')}this.blendMode!==t.currentBlendMode&&(t.currentBlendMode=this.blendMode,e.globalCompositeOperation=t.blendModes[t.currentBlendMode]);var n=this.tilePosition,a=this.tileScale;for(n.x%=this.tilingTexture.base.width,n.y%=this.tilingTexture.base.height,e.scale(a.x,a.y),e.translate(n.x+this.anchor.x*-this._width,n.y+this.anchor.y*-this._height),e.fillStyle=this.__tilePattern,e.fillRect(-n.x,-n.y,this._width/a.x,this._height/a.y),e.scale(1/a.x,1/a.y),e.translate(-n.x+this.anchor.x*this._width,-n.y+this.anchor.y*this._height),this._mask&&t.maskManager.popMask(t),i=0,s=this.children.length;i<s;i++)this.children[i].renderCanvas(t)}},getBounds:function(){var t=this._width,e=this._height,i=t*(1-this.anchor.x),s=t*-this.anchor.x,r=e*(1-this.anchor.y),h=e*-this.anchor.y,n=this.worldTransform,a=n.a,l=n.b,o=n.c,c=n.d,u=n.tx,x=n.ty,g=a*s+o*h+u,f=c*h+l*s+x,d=a*i+o*h+u,p=c*h+l*i+x,T=a*i+o*r+u,y=c*r+l*i+x,w=a*s+o*r+u,_=c*r+l*s+x,b=-1/0,v=-1/0,S=1/0,m=1/0;S=w<(S=T<(S=d<(S=g<S?g:S)?d:S)?T:S)?w:S,m=_<(m=y<(m=p<(m=f<m?f:m)?p:m)?y:m)?_:m,b=w>(b=T>(b=d>(b=g>b?g:b)?d:b)?T:b)?w:b,v=_>(v=y>(v=p>(v=f>v?f:v)?p:v)?y:v)?_:v;var B=this._bounds;return B.x=S,B.width=b-S,B.y=m,B.height=v-m,this._currentBounds=B,B},generateTilingTexture:function(t){if(this.texture.base.valid){var e,i,s,r=this.originalTexture||this.texture,h=r.frame;t?(e=Tiny.Math.getNextPow2(h.width),i=Tiny.Math.getNextPow2(h.height),!0):(r.trim?(e=r.trim.width,i=r.trim.height):(e=h.width,i=h.height),!0),this.tilingTexture&&this.tilingTexture.isTiling?((s=this.tilingTexture.canvasBuffer).resize(e,i),this.tilingTexture.base.width=e,this.tilingTexture.base.height=i,this.tilingTexture.needsUpdate=!0):(s=new Tiny.CanvasBuffer(e,i),this.tilingTexture=new Tiny.Texture(s.canvas),this.tilingTexture.canvasBuffer=s,this.tilingTexture.isTiling=!0),s.context.drawImage(r.base.source,r.crop.x,r.crop.y,r.crop.width,r.crop.height,0,0,e,i),this.tileScaleOffset.x=h.width/e,this.tileScaleOffset.y=h.height/i,this.refreshTexture=!1,this.originalTexture=this.texture,this.texture=this.tilingTexture,this.tilingTexture.base._powerOf2=!0}},destroy:function(){Tiny.Sprite.prototype.destroy.call(this),this.tileScale=null,this.tileScaleOffset=null,this.tilePosition=null,this.tilingTexture&&(this.tilingTexture.destroy(!0),this.tilingTexture=null)}});i(548);Tiny.TilingSprite=t}()}();