-
-
Notifications
You must be signed in to change notification settings - Fork 93
Images
This entry describes in detail how Myra deals with images.
IRenderable represents something with size that can draw itself in the specified rectangle with the specified color. Many widgets properties such as Widget.Background or Image.Renderable have IRenderable type.
Myra provides 3 IRenderable implementation: TextureRegion, NinePatchRegion and ColoredRegion.
TextureRegion describes rectangle in the texture. TextureRegion implements IRenderable. Therefore following code will work:
// 'texture' is object of type Texture2D
widget.Background = new TextureRegion(texture, new Rectangle(10, 10, 50, 50));
Also following:
// If 2nd parameter is omitted, then TextureRegion covers the whole texture
image.Renderable = new TextureRegion(texture);
NinePatchRegion represents region with unstrechable border and strechable center. It could be used following way:
widget.Background = new NinePatchRegion(texture, new Rectangle(10, 10, 50, 50),
new PaddingInfo {Left = 2, Right = 2,
Top = 2, Bottom = 2});
ColoredRegion represents TextureRegion and Color. It could be used when one needs to draw single TextureRegion in multiple colors. I.e. following code will work:
widget.Background = new ColoredRegion(textureRegion, Color.Blue);
And following
image.Renderable = new ColoredRegion(ninePatchRegion, Color.Red);
Myra default assets contain white TextureRegion. It could be used if one needs to make solid renderable filled with specified color. I.e. following code will make widget's background violet:
widget.Background = new ColoredRegion(DefaultAssets.WhiteRegion, Color.Violet);
TextureRegionAtlas is collection of texture regions(each could be nine patch) accessible by string key.
It could be serialized to json with following look: default_ui_skin_atlas.json
It's structure is quite straightforward. Only thing worthy to mention is that "type" equals "0" means ordinary TextureRegion, while "type" equals "1" means NinePatchRegion.
Following code loads it from json:
// Json is string with
TextureRegionAtlas spriteSheet = TextureRegionAtlas.FromJson(json, UIBitmap);
And following code saves it to json:
string json = spriteSheet.ToJson();