//--------------------------------------------------------------------------- protected void DrawLine(SpriteBatch batch, Texture2D tex, Vector2 start, Vector2 end, CameraData data) { Vector2 location = start.ToLocal(data) + Vector2.One; float length = Vector2.Distance(start, end); float angle = (float)Math.Atan2(end.Y - start.Y, end.X - start.X); batch.Draw(tex, new Rectangle((int)location.X, (int)location.Y, (int)length, 2), tex.Bounds, GetDebugColor(), angle, Vector2.Zero, SpriteEffects.None, 1.0f); }
//--------------------------------------------------------------------------- public RenderTarget2D Render(SpriteBatch batch, float deltaTime) { TransformComponent transform = GetComponent <TransformComponent>(); if (transform != null) { CameraData data = new CameraData(transform.Location.To2D(), m_ComponentsTarget.Width, m_ComponentsTarget.Height); Device.SetRenderTarget(m_ComponentsTarget); Device.Clear(Color.Black); if (m_ComponentsTarget != null) { if (BackgroundTexture != null) { Vector2 location = transform.Location.To2D(); batch.Begin(SpriteSortMode.Deferred, null, SamplerState.LinearWrap, null, null); batch.Draw( BackgroundTexture, Vector2.Zero, new Rectangle((int)(location.X % BackgroundTexture.Width), (int)(location.Y % BackgroundTexture.Height), m_ComponentsTarget.Width, m_ComponentsTarget.Height), Color.White, 0, Vector2.Zero, 1f, SpriteEffects.None, 0); batch.End(); } batch.Begin(SpriteSortMode.FrontToBack, null, SamplerState.PointClamp); DrawStage(batch, data); ComponentManager.Get().DrawComponents(batch, data, deltaTime); batch.End(); if (IsLightingEnabled && m_LightingTarget != null && LightingEffect != null) { BlurEffect.Parameters["blurSizeHorizontal"].SetValue(1.0f / m_MainTarget.Width); BlurEffect.Parameters["blurSizeVertical"].SetValue(1.0f / m_MainTarget.Height); LightingEffect.Parameters["horizontalOffset"].SetValue(transform.Location.X + m_Time * 100.0f); LightingEffect.Parameters["verticalOffset"].SetValue(transform.Location.Y + m_Time * 100.0f); LightingEffect.Parameters["time"].SetValue(m_Time / 5.0f); DrawLightMask(batch, data, deltaTime); if (m_MainTarget != null) { LightingEffect.Parameters["lightMask"].SetValue(m_LightingTarget); m_EffectWrapper.ApplyEffects(batch, m_ComponentsTarget, m_MainTarget, m_PostEffects); m_EffectWrapper.ApplyEffects(batch, m_MainTarget, m_ShadowTarget, new List <Effect>() { BloomExtractEffect, BlurEffect }); BloomCombineEffect.Parameters["bloom"].SetValue(m_ShadowTarget); m_EffectWrapper.ApplyEffects(batch, m_MainTarget, m_ComponentsTarget, new List <Effect>() { BloomCombineEffect }); return(m_MainTarget); } return(m_LightingTarget); } } } return(m_ComponentsTarget); }
//--------------------------------------------------------------------------- public abstract void Draw(SpriteBatch batch, CameraData data, float deltaTime);
//--------------------------------------------------------------------------- private bool IsValidDistance(CameraData data, Vector3 center) { return(Vector2.Distance(data.Center, center.To2D()) <= Math.Sqrt(Math.Pow(data.Width, 2) + Math.Pow(data.Height, 2)) / 2); }