CUISprite is a wrapper for monogame Texture2D and additional props like SourceRect, Rotation, DrawMode etc
Multiple sprites can have same texture
CUISprite constructors use CUITextureManager to retrieve textures without duplicates, so creating new sprites doesn't create copies of textures
CUISprites are very similar to vanilla Sprites, but i don't use vanilla Sprites because they has a lot of side effects
CUISprite Properties
- CUISptite.BaseFolder - if not null the used for relative paths, set it before creating sprites
- Effects - enum, controlls sprite flipping [None, FlipHorizontally, FlipVertically]
- DrawMode:
- Resize - Sprite is resized to CUIComponent
- Wrap - Texture is looped
- Static - Sprite ignores CUIComponent position, like it's drawn on background
- DeepStatic - ???
- SourceRect - Part of the texture that is drawn, doesn't work in Wrap mode because it'll loop the whole texture
- Texture - the texture
- Rotation - Sprite Rotation around Origin in radians
- RotationAngle - Accessor for Rotation in degrees
- Origin - Origin of rotation on the texture in pixels
- RelativeOrigin - Accessor for Origin with Vector2(0..1,0..1)
- Offset - Draw offset relative to CUIComponent Position, it compensates Origin
How to create them
- new CUISprite() - 1x1 white sprite
- new CUISprite(string path, Rectangle? sourceRect = null, string baseFolder = null) - Loads sprite from a file
- new CUISprite(Texture2D texture, Rectangle? sourceRect = null) - Creates with existing texture
- CUISprite.FromVanilla(Sprite sprite) - Creates CUISprite from vanilla Sprite
- CUISprite.FromName(string name) - Creates CUISprite from vanilla GUI Sprite in GUIStyle.ComponentStyles
- CUI.TextureManager.GetSprite(string path, Rectangle? sourceRect = null, CUISpriteDrawMode? drawMode = null, SpriteEffects? effects = null) - Also creates new CUISprite
- CUI.TextureManager.GetCUISprite(int x, int y, CUISpriteDrawMode? drawMode = null, SpriteEffects? effects = null) - Creates a sprite from 32x32 square in CUI.png with (x,y) coordinates
How texture paths are resolved
TextureManager first tries to load texture from CUI.AssetsPath, then from CUI.PGNAssets, then directly from path
If not found it will return default texture
If sprite is created with CUISprite constructor, CUISptite.BaseFolder is set and that file actually exists in BaseFolder then CUISprite will pass path relative to BaseFolder into TextureManager.GetSprite