private TextSprite CreateSprite(object key, string renderedStringBuilder, int frameNumber, bool cached, GraphicsDevice device) { // First try to find an existing sprite to reuse for (int i = 0; i < sprites.Count; i++) { // If it was last used before the immediately previous frame, assume it is free to use: if (sprites[i].cached == cached && sprites[i].foundOnFrame < frameNumber - 1) { TextSpriteInstance instance = sprites[i]; instance.key = key; instance.renderedStringBuilder = renderedStringBuilder; instance.foundOnFrame = frameNumber; sprites[i] = instance; return(instance.value); } } // If no sprite to reuse was found... TextSprite sprite = new TextSprite(this, cached); sprites.Add(new TextSpriteInstance() { key = key, value = sprite, renderedStringBuilder = renderedStringBuilder, foundOnFrame = frameNumber, cached = cached }); device.AddSprite(sprite); return(sprite); }
internal ImageSprite GetSprite(ImageSourceId id) { List <ImageSprite> spriteList; sprites.TryGetValue(id, out spriteList); if (spriteList == null) { spriteList = new List <ImageSprite>(); sprites.Add(id, spriteList); } int frame = GraphicsDevice.CurrentSpriteFrameNumber; foreach (ImageSprite sprite in spriteList) { if (sprite.usedOnFrame != frame) { return(sprite); } } // No suitable sprite found, add one: ImageSprite createSprite = new ImageSprite(this, id); GraphicsDevice.AddSprite(createSprite); spriteList.Add(createSprite); return(createSprite); }
private TextSprite CreateSprite(object key, string renderedStringBuilder, int frameNumber, bool cached, GraphicsDevice device) { // First try to find an existing sprite to reuse for(int i = 0; i < sprites.Count; i++) { // If it was last used before the immediately previous frame, assume it is free to use: if(sprites[i].cached == cached && sprites[i].foundOnFrame < frameNumber-1) { TextSpriteInstance instance = sprites[i]; instance.key = key; instance.renderedStringBuilder = renderedStringBuilder; instance.foundOnFrame = frameNumber; sprites[i] = instance; return instance.value; } } // If no sprite to reuse was found... TextSprite sprite = new TextSprite(this, cached); sprites.Add(new TextSpriteInstance() { key = key, value = sprite, renderedStringBuilder = renderedStringBuilder, foundOnFrame = frameNumber, cached = cached }); device.AddSprite(sprite); return sprite; }