public Sprite GetSprite(string name) { Sprite sprite = Optional <Sprite>(name); if (sprite != null) { return(sprite); } try { TextureRegion textureRegion = GetRegion(name); if (textureRegion is TextureAtlas.AtlasRegion) { TextureAtlas.AtlasRegion region = textureRegion as TextureAtlas.AtlasRegion; if (region.Rotate || region.PackedWidth != region.OriginalWidth || region.PackedHeight != region.OriginalHeight) { sprite = new TextureAtlas.AtlasSprite(region); } } if (sprite == null) { sprite = new Sprite(textureRegion); } Add <Sprite>(name, sprite); return(sprite); } catch { throw new Exception("No Sprite, TextureRegion, or Texture registered with name: " + name); } }
public ISceneDrawable NewDrawable(ISceneDrawable drawable, Xna.Color tint) { if (drawable is TextureRegionDrawable) { TextureRegion region = (drawable as TextureRegionDrawable).Region; Sprite sprite; if (region is TextureAtlas.AtlasRegion) { sprite = new TextureAtlas.AtlasSprite(region as TextureAtlas.AtlasRegion); } else { sprite = new Sprite(region); } sprite.Color = tint; return(new SpriteDrawable(sprite)); } if (drawable is NinePatchDrawable) { NinePatchDrawable patchDrawable = new NinePatchDrawable(drawable as NinePatchDrawable); patchDrawable.Patch = new NinePatch(patchDrawable.Patch, tint); return(patchDrawable); } if (drawable is SpriteDrawable) { SpriteDrawable spriteDrawable = new SpriteDrawable(drawable as SpriteDrawable); Sprite sprite = spriteDrawable.Sprite; if (sprite is TextureAtlas.AtlasSprite) { sprite = new TextureAtlas.AtlasSprite(sprite as TextureAtlas.AtlasSprite); } else { sprite = new Sprite(sprite); } sprite.Color = tint; spriteDrawable.Sprite = sprite; return(spriteDrawable); } throw new Exception("Unable to copy, unknown drawbale type: " + drawable.GetType()); }