private void BatchLeafSprite(LeafSprite sprite, float sizeMultiplier)
        {
            float   scale         = sprite.Size / (float)textures[sprite.TextureIndex].Width * sizeMultiplier;
            Vector2 textureCenter = new Vector2(textures[sprite.TextureIndex].Width, textures[sprite.TextureIndex].Height) / 2.0f;

            spriteBatch.Draw(textures[sprite.TextureIndex], sprite.Center, null, Color.White, sprite.Angle, textureCenter, scale, SpriteEffects.None, 0.0f);
        }
        private LeafSprite FindClosestSpriteUnderPoint(Vector2 searchPoint)
        {
            float      closestDistanceSQ = 1e20f;
            LeafSprite closest           = null;

            for (int i = 0; i < sprites.Count; i++)
            {
                LeafSprite sprite = sprites[i];

                // Determine if cursor is inside the sprite's rectangle
                Vector2 leafToCursor = searchPoint - sprite.Center;
                Vector2 localX       = new Vector2((float)Math.Cos(sprite.Angle), (float)Math.Sin(sprite.Angle));
                Vector2 localY       = new Vector2(-localX.Y, localX.X);
                Vector2 localCoords  = new Vector2(
                    Vector2.Dot(leafToCursor, localX),
                    Vector2.Dot(leafToCursor, localY)
                    );

                // If outside rectangle, skip this sprite
                if (Math.Abs(localCoords.X) > sprite.Size / 2 || Math.Abs(localCoords.Y) > sprite.Size / 2)
                {
                    continue;
                }

                float distanceSQ = localCoords.LengthSquared();
                if (distanceSQ < closestDistanceSQ)
                {
                    closestDistanceSQ = distanceSQ;
                    closest           = sprite;
                }
            }
            return(closest);
        }
        private void DeleteSpriteAtCursor()
        {
            LeafSprite sprite = FindClosestSpriteUnderPoint(MousePos);

            if (sprite == null)
            {
                return;
            }

            sprites.Remove(sprite);
        }
 private void DrawBackgroundLeaves()
 {
     GraphicsDevice.RenderState.ColorWriteChannels = ColorWriteChannels.Red | ColorWriteChannels.Green | ColorWriteChannels.Blue;
     spriteBatch.Begin(SpriteBlendMode.AlphaBlend);
     for (int i = 0; i < sprites.Count; i++)
     {
         LeafSprite sprite = sprites[sprites.Count - i - 1];
         BatchLeafSprite(sprite, 2.0f);
     }
     spriteBatch.End();
     GraphicsDevice.RenderState.ColorWriteChannels = ColorWriteChannels.All;
 }
Example #5
0
        private void DrawBackgroundLeaves()
        {
            BlendState savedBlendState = GraphicsDevice.BlendState;

            GraphicsDevice.BlendState = ChangeColorWriteChannels(savedBlendState,
                                                                 ColorWriteChannels.Red | ColorWriteChannels.Green | ColorWriteChannels.Blue);
            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
            for (int i = 0; i < sprites.Count; i++)
            {
                LeafSprite sprite = sprites[sprites.Count - i - 1];
                BatchLeafSprite(sprite, 2.0f);
            }
            spriteBatch.End();
            GraphicsDevice.BlendState = ChangeColorWriteChannels(savedBlendState,
                                                                 ColorWriteChannels.All);
        }
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            textures = new Texture2D[textureFilenames.Length];
            for (int i = 0; i < textures.Length; i++)
            {
                textures[i] = Content.Load <Texture2D>(String.Format(textureFilenameFormat, textureFilenames[i]));
            }

            renderTarget = new RenderTarget2D(GraphicsDevice, 256, 256, 1, SurfaceFormat.Color);

            mouseSprite = new LeafSprite(Vector2.Zero, 32, 0, 0);

            imageSize = new Vector2(256, 256);
            pivot     = imageSize / 2.0f;

            pivotTexture = Content.Load <Texture2D>("Textures/Pivot");
        }
 private void BatchLeafSprite(LeafSprite sprite)
 {
     BatchLeafSprite(sprite, 1.0f);
 }
 private void BatchLeafSprite(LeafSprite sprite, float sizeMultiplier)
 {
     float scale = sprite.Size / (float)textures[sprite.TextureIndex].Width * sizeMultiplier;
     Vector2 textureCenter = new Vector2(textures[sprite.TextureIndex].Width, textures[sprite.TextureIndex].Height) / 2.0f;
     spriteBatch.Draw(textures[sprite.TextureIndex], sprite.Center, null, Color.White, sprite.Angle, textureCenter, scale, SpriteEffects.None, 0.0f);
 }
 private void BatchLeafSprite(LeafSprite sprite)
 {
     BatchLeafSprite(sprite, 1.0f);
 }
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            textures = new Texture2D[textureFilenames.Length];
            for (int i = 0; i < textures.Length; i++)
			{
                textures[i] = Content.Load<Texture2D>(String.Format(textureFilenameFormat, textureFilenames[i]));
			}

            renderTarget = new RenderTarget2D(GraphicsDevice, 256, 256, 1, SurfaceFormat.Color);

            mouseSprite = new LeafSprite(Vector2.Zero, 32, 0, 0);

            imageSize = new Vector2(256, 256);
            pivot = imageSize / 2.0f;

            pivotTexture = Content.Load<Texture2D>("Textures/Pivot");
        }