/// <summary> /// Creates a sprite with default settings. /// </summary> /// <param name="textureUri">The relative project path for a texture.</param> public SpriteBatchSprite(string textureUri) { cachedColorAlphaBlend = Color.White; cachedOrigin = Vector2.Zero; cachedScale = Vector2.One; cachedSize = new Tuple <int, int>(0, 0); cachedTexture = null; cachedSrcRect = Rectangle.Empty; cachedDestRect = Rectangle.Empty; origin = SpriteOrigin.TopLeft; performBlendingPremultiplied = true; position = Vector2.Zero; size = SpriteSize.Empty; textureAlphaBlend = 1f; textureColorBlend = Color.White; textureSourceRect = SmoothRect.Empty; this.textureUri = textureUri; Angle = 0f; Depth = 0f; TextureMirroring = SpriteEffects.None; UseDepthInDraw = false; // Computes all cached values. cachedTexture = Texture2DManager.Get(textureUri); bool isCachedTextureLoaded = cachedTexture != null && !cachedTexture.IsDisposed; ComputeColorAlphaBlend(); if (Origin.Kind != SpriteOriginKind.Percentile || isCachedTextureLoaded) { ComputeOrigin(); } if (Size.IsEmpty || Size.Kind == SpriteSizeKind.Scaling || isCachedTextureLoaded) { ComputeScale(); } if (Size.Kind != SpriteSizeKind.Scaling || isCachedTextureLoaded) { ComputeSizeAndDestRectangle(); } if (!TextureSourceRect.IsEmpty || isCachedTextureLoaded) { ComputeSourceRectangle(); } }
/// <summary> /// Creates a deep copy of a sprite from another. /// </summary> /// <param name="sprite">The sprite to copy.</param> public SpriteBatchSprite(SpriteBatchSprite sprite) { Angle = sprite.Angle; cachedColorAlphaBlend = sprite.cachedColorAlphaBlend; cachedDestRect = sprite.cachedDestRect; cachedOrigin = sprite.cachedOrigin; cachedScale = sprite.cachedScale; cachedSize = sprite.cachedSize; cachedSrcRect = sprite.cachedSrcRect; cachedTexture = sprite.cachedTexture; Depth = sprite.Depth; UseDepthInDraw = sprite.UseDepthInDraw; origin = sprite.Origin; performBlendingPremultiplied = sprite.PerformBlendingPremultiplied; position = sprite.Position; size = sprite.Size; textureAlphaBlend = sprite.TextureAlphaBlend; textureColorBlend = sprite.TextureColorBlend; TextureMirroring = sprite.TextureMirroring; textureSourceRect = sprite.TextureSourceRect; textureUri = sprite.textureUri; }