コード例 #1
0
ファイル: SpriteFontTTF.cs プロジェクト: meds/ChicksnVixens
        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);
        }
コード例 #2
0
ファイル: Texture2D.cs プロジェクト: meds/ChicksnVixens
        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);
        }
コード例 #3
0
ファイル: SpriteFontTTF.cs プロジェクト: jlyonsmith/ExEnCopy
        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;
        }