public RectF get( int index ) { float x = index % cols; float y = index / cols; float l = uvLeft + x * uvWidth; float t = uvTop + y * uvHeight; return new RectF( l, t, l + uvWidth, t + uvHeight ); }
public TextureFilm( TextureFilm atlas, Object key, int width, int height ) { texture = atlas.texture; texWidth = atlas.texWidth; texHeight = atlas.texHeight; RectF patch = atlas.get( key ); float uw = (float)width / texWidth; float vh = (float)height / texHeight; int cols = (int)(width( patch ) / width); int rows = (int)(height( patch ) / height); for (int i=0; i < rows; i++) { for (int j=0; j < cols; j++) { RectF rect = new RectF( j * uw, i * vh, (j+1) * uw, (i+1) * vh ); rect.shift( patch.left, patch.top ); add( i * cols + j, rect ); } } }
public static Image avatar( HeroClass cl, int armorTier ) { RectF patch = tiers().get( armorTier ); Image avatar = new Image( cl.spritesheet() ); RectF frame = avatar.texture.uvRect( 1, 0, FRAME_WIDTH, FRAME_HEIGHT ); frame.shift( patch.left, patch.top ); avatar.frame( frame ); return avatar; } }
public RectF setPos( float x, float y ) { return set( x, y, x + (right - left), y + (bottom - top)); }
public float height( RectF frame ) { return frame.height() * texHeight; } }
public float width( RectF frame ) { return frame.width() * texWidth; }
public RectF union( Point p ) { return union( p.x, p.y ); }
public RectF shrink() { return shrink( 1 ); }
public TextureFilm( TextureFilm atlas, Object key, int width, int height ) { texture = atlas.texture; texWidth = atlas.texWidth; texHeight = atlas.texHeight; RectF patch = atlas.get( key ); float uw = (float)width / texWidth; float vh = (float)height / texHeight; int cols = (int)(width( patch ) / width); int rows = (int)(height( patch ) / height); for (int i=0; i < rows; i++) { for (int j=0; j < cols; j++) { RectF rect = new RectF( j * uw, i * vh, (j+1) * uw, (i+1) * vh ); rect.shift( patch.left, patch.top ); add( i * cols + j, rect ); } } }
public static Image avatar( HeroClass cl, int armorTier ) { RectF patch = tiers().get( armorTier ); Image avatar = new Image( cl.spritesheet() ); RectF frame = avatar.texture.uvRect( 1, 0, FRAME_WIDTH, FRAME_HEIGHT ); frame.shift( patch.left, patch.top ); avatar.frame( frame ); return avatar; } }
public RectF shift( float x, float y ) { return set( left+x, top+y, right+x, bottom+y ); }
public float height( RectF rect ) { return rect.height() * tx.height; }
public float width( RectF rect ) { return rect.width() * tx.width; }
public RectF union( Point p ) { return union( p.x, p.y ); }
public RectF shrink() { return shrink( 1 ); }
public RectF uvRect( float left, float top, float right, float bottom ) { return new RectF( left / width, top / height, right / width, bottom / height ); } }
public RectF set( Rect rect ) { return set( rect.left, rect.top, rect.right, rect.bottom ); }