Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1051 | chris | 1 | package com.gebauz.bauzoid.graphics.spritex; |
| 2 | |||
| 3 | import com.badlogic.gdx.graphics.Texture; |
||
| 4 | |||
| 5 | public class SpriteRegion |
||
| 6 | { |
||
| 7 | public float left; |
||
| 8 | public float top; |
||
| 9 | public float bottom; |
||
| 10 | public float right; |
||
| 11 | |||
| 12 | /** Constructor. */ |
||
| 13 | public SpriteRegion(Texture referenceTexture, float x, float y, float w, float h) |
||
| 14 | { |
||
| 15 | setAbsolute(referenceTexture, x, y, w, h); |
||
| 16 | } |
||
| 17 | |||
| 18 | /** Constructor - sets region by relative texture coordinates. */ |
||
| 19 | public SpriteRegion(float _top, float _left, float _right, float _bottom) |
||
| 20 | { |
||
| 21 | top = _top; |
||
| 22 | left = _left; |
||
| 23 | right = _right; |
||
| 24 | bottom = _bottom; |
||
| 25 | } |
||
| 26 | |||
| 27 | /** Set region by absolute pixel coordinates relative to the specified texture. |
||
| 28 | * Coordinates are in absolute texel space. |
||
| 29 | */ |
||
| 30 | public void setAbsolute(Texture referenceTexture, float x, float y, float w, float h) |
||
| 31 | { |
||
| 32 | left = x / referenceTexture.getWidth(); |
||
| 33 | top = y / referenceTexture.getHeight(); |
||
| 34 | right = left + (w / referenceTexture.getWidth()); |
||
| 35 | bottom = top + (h / referenceTexture.getHeight()); |
||
| 36 | } |
||
| 37 | |||
| 38 | public float getWidth() |
||
| 39 | { |
||
| 40 | return (right-left); |
||
| 41 | } |
||
| 42 | |||
| 43 | public float getHeight() |
||
| 44 | { |
||
| 45 | return (bottom-top); |
||
| 46 | } |
||
| 47 | } |