コード例 #1
0
        public void BeginDraw(Camera camera)
        {
            SpriteBatch spriteBatch = OGE.SpriteBatch;
            Vector2 origin = new Vector2(lightTexture.Width / 2, lightTexture.Height / 2);
            Vector2 cameraPosition;
            Rectangle lightRectangle;
            int width, height;

            OGE.GraphicDevice.SetRenderTarget(renderTarget);
            OGE.GraphicDevice.Clear(new Color(AmbientLight, AmbientLight, AmbientLight));

            spriteBatch.Begin(OGE.SpriteSortMode, OGE.BlendState);

            foreach (LightSource light in lightingSources)
            {
                width = (int)(lightTexture.Width * light.Scale);
                height = (int)(lightTexture.Height * light.Scale);
                lightRectangle = new Rectangle((int)(light.Position.X - width / 2), (int)(light.Position.Y - height / 2), width, height);

                if (camera.CheckRectangleInCamera(lightRectangle))
                {
                    cameraPosition = camera.ConvertToCamera(light.Position);
                    spriteBatch.Draw(lightTexture, cameraPosition, null, light.TintColor * light.Alpha, 0, origin,
                        light.Scale, SpriteEffects.None, 0);
                }
            }

            spriteBatch.End();

            OGE.GraphicDevice.SetRenderTarget(null);
        }
コード例 #2
0
        public override void Draw(Vector2 position, Camera camera)
        {
            SpriteBatch spriteBatch = OGE.SpriteBatch;

            if (!camera.CheckRectangleInCamera(new Rectangle((int)position.X, (int)position.Y, Width, Height)))
            {
                return;
            }

            spriteBatch.Begin(OGE.SpriteSortMode, BlendState.Additive);

            spriteBatch.Draw(texture, camera.ConvertToCamera(position), sourceRectangle, tintColor * Alpha, angle, origin, scale, flipping, 0);

            spriteBatch.End();
        }
コード例 #3
0
        public override void Draw(Vector2 position, Camera camera)
        {
            SpriteBatch spriteBatch = OGE.SpriteBatch;

            if (!camera.CheckRectangleInCamera(new Rectangle((int)position.X, (int)position.Y, Width, Height)))
            {
                return;
            }

            spriteBatch.Begin(OGE.SpriteSortMode, OGE.BlendState);

            spriteBatch.Draw(texture, camera.ConvertToCamera(position + new Vector2(0, 0)), sourceRectangle, tintColor * Alpha,
                angle, origin, scale, SpriteEffects.FlipHorizontally, 0);
            spriteBatch.Draw(texture, camera.ConvertToCamera(position + new Vector2(camera.Width - Width, 0)), sourceRectangle, tintColor * Alpha,
                angle, origin, scale, SpriteEffects.None, 0);
            spriteBatch.Draw(texture, camera.ConvertToCamera(position + new Vector2(0, camera.Height - Height)), sourceRectangle, tintColor * Alpha,
                angle, origin, scale, SpriteEffects.FlipHorizontally | SpriteEffects.FlipVertically, 0);
            spriteBatch.Draw(texture, camera.ConvertToCamera(position + new Vector2(camera.Width - Width, camera.Height - Height)), sourceRectangle, tintColor * Alpha,
                angle, origin, scale, SpriteEffects.FlipVertically, 0);

            spriteBatch.End();
        }
コード例 #4
0
ファイル: Image.cs プロジェクト: amidos2006/CleanEmUp
        /// <summary>
        /// Draw the texture in the correct position
        /// </summary>
        /// <param name="position">position of the image to be drawn at</param>
        /// <param name="camera">camera position in the scene</param>
        public virtual void Draw(Vector2 position, Camera camera)
        {
            SpriteBatch spriteBatch = OGE.SpriteBatch;

            Vector2 leftUpperCorner = OGE.GetLeftUpperCorner(position, origin);

            if (!camera.CheckRectangleInCamera(new Rectangle((int)leftUpperCorner.X, (int)leftUpperCorner.Y, Width, Height)))
            {
                return;
            }

            spriteBatch.Begin(OGE.SpriteSortMode, OGE.BlendState);

            spriteBatch.Draw(texture, camera.ConvertToCamera(position), sourceRectangle, tintColor, angle, origin, scale, flipping, 0);

            spriteBatch.End();
        }
コード例 #5
0
        public void BeginDraw(Camera camera)
        {
            //CleanUpSystem(true);

            SpriteBatch spriteBatch = OGE.SpriteBatch;
            Vector2 origin;
            Vector2 cameraPosition;
            Rectangle particleRectangle;

            OGE.GraphicDevice.SetRenderTarget(renderTarget);
            OGE.GraphicDevice.Clear(new Color(0, 0, 0, 0));

            spriteBatch.Begin(OGE.SpriteSortMode, blendState);

            spriteBatch.Draw(oldRenderTarget, camera.ConvertToCamera(oldPosition), Color.White * AlphaOldTarget);

            foreach (Particle particle in particles)
            {
                origin = new Vector2(particle.Texture.Width/2,particle.Texture.Height/2);
                particleRectangle = new Rectangle((int)(particle.Position.X - particle.Texture.Width / 2),
                    (int)(particle.Position.Y - particle.Texture.Height / 2), particle.Texture.Width, particle.Texture.Height);

                if(camera.CheckRectangleInCamera(particleRectangle))
                {
                    cameraPosition = camera.ConvertToCamera(particle.Position);
                    spriteBatch.Draw(particle.Texture, cameraPosition, particle.SourceRectangle, particle.ParticleColor * particle.Alpha,
                        MathHelper.ToRadians(particle.Angle), origin, particle.Scale, SpriteEffects.None, 0);
                }
            }

            spriteBatch.End();

            OGE.GraphicDevice.SetRenderTarget(oldRenderTarget);
            OGE.GraphicDevice.Clear(new Color(0, 0, 0, 0));
            spriteBatch.Begin(OGE.SpriteSortMode, OGE.BlendState);
            spriteBatch.Draw(renderTarget, new Vector2(), Color.White);
            spriteBatch.End();
            oldPosition.X = camera.X;
            oldPosition.Y = camera.Y;

            OGE.GraphicDevice.SetRenderTarget(null);
        }