Пример #1
0
        public void EnsureLazyLoaded()
        {
            if (!lazyLoad || texture != null)
            {
                return;
            }

            Vector4 sourceVector = Vector4.Zero;
            bool    temp2        = false;

            LoadTexture(ref sourceVector, ref temp2, preMultipliedAlpha);
            if (sourceRect.Width == 0 && sourceRect.Height == 0)
            {
                sourceRect     = new Rectangle((int)sourceVector.X, (int)sourceVector.Y, (int)sourceVector.Z, (int)sourceVector.W);
                size           = SourceElement.GetAttributeVector2("size", Vector2.One);
                size.X        *= sourceRect.Width;
                size.Y        *= sourceRect.Height;
                RelativeOrigin = SourceElement.GetAttributeVector2("origin", new Vector2(0.5f, 0.5f));
            }
            foreach (Sprite s in list)
            {
                if (s == this)
                {
                    continue;
                }
                if (s.FullPath == FullPath && s.texture != null)
                {
                    s.texture = texture;
                }
            }
        }
Пример #2
0
        public void EnsureLazyLoaded(bool isAsync = false)
        {
            if (!LazyLoad || texture != null || cannotBeLoaded || loadingAsync)
            {
                return;
            }
            loadingAsync = isAsync;

            Vector4 sourceVector   = Vector4.Zero;
            bool    temp2          = false;
            int     maxLoadRetries = 3;

            for (int i = 0; i <= maxLoadRetries; i++)
            {
                try
                {
                    LoadTexture(ref sourceVector, ref temp2);
                }
                catch (System.IO.IOException)
                {
                    if (i == maxLoadRetries || !File.Exists(FilePath))
                    {
                        throw;
                    }
                    DebugConsole.NewMessage("Loading sprite \"" + FilePath + "\" failed, retrying in 250 ms...");
                    System.Threading.Thread.Sleep(500);
                }
            }

            if (sourceRect.Width == 0 && sourceRect.Height == 0)
            {
                sourceRect     = new Rectangle((int)sourceVector.X, (int)sourceVector.Y, (int)sourceVector.Z, (int)sourceVector.W);
                size           = SourceElement.GetAttributeVector2("size", Vector2.One);
                size.X        *= sourceRect.Width;
                size.Y        *= sourceRect.Height;
                RelativeOrigin = SourceElement.GetAttributeVector2("origin", new Vector2(0.5f, 0.5f));
            }
            if (texture == null)
            {
                cannotBeLoaded = true;
            }
        }
Пример #3
0
        public void EnsureLazyLoaded()
        {
            if (!LazyLoad || texture != null || cannotBeLoaded)
            {
                return;
            }

            Vector4 sourceVector = Vector4.Zero;
            bool    temp2        = false;

            LoadTexture(ref sourceVector, ref temp2);
            if (sourceRect.Width == 0 && sourceRect.Height == 0)
            {
                sourceRect     = new Rectangle((int)sourceVector.X, (int)sourceVector.Y, (int)sourceVector.Z, (int)sourceVector.W);
                size           = SourceElement.GetAttributeVector2("size", Vector2.One);
                size.X        *= sourceRect.Width;
                size.Y        *= sourceRect.Height;
                RelativeOrigin = SourceElement.GetAttributeVector2("origin", new Vector2(0.5f, 0.5f));
            }
            if (texture == null)
            {
                cannotBeLoaded = true;
            }
        }