private void DrawSpriteBatchEntities(Camera camera, byte groupMask, float dt, float betweenFrameAlpha, Camera debugCamera) { Matrix transformMatrix = debugCamera == null?camera.GetInterpolatedTransformMatrix(betweenFrameAlpha) : debugCamera.GetInterpolatedTransformMatrix(betweenFrameAlpha); SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.AnisotropicClamp, null, null, null, transformMatrix); foreach (Entity entity in _spriteEntities) { SpriteComponent spriteComp = entity.GetComponent <SpriteComponent>(); if (spriteComp.Hidden || (spriteComp.RenderGroup & groupMask) == 0) { continue; } TransformComponent transformComp = entity.GetComponent <TransformComponent>(); BoundingRect boundRect = spriteComp.GetAABB(transformComp.Scale); boundRect.Min += transformComp.Position; boundRect.Max += transformComp.Position; if (!boundRect.Intersects(camera.BoundingRect) && CVars.Get <bool>("debug_show_render_culling")) { continue; } Vector2 position; float rotation; float transformScale; transformComp.Interpolate(betweenFrameAlpha, out position, out rotation, out transformScale); Vector2 scale = new Vector2(spriteComp.Bounds.X / spriteComp.Texture.Width, spriteComp.Bounds.Y / spriteComp.Texture.Height); Vector2 origin = new Vector2(spriteComp.Texture.Bounds.Width, spriteComp.Texture.Bounds.Height) * HalfHalf; AnimationComponent animationComp = entity.GetComponent <AnimationComponent>(); if (animationComp != null && animationComp.ActiveAnimationIndex > -1) { Rectangle sourceRectangle = animationComp.Animations[animationComp.ActiveAnimationIndex].TextureRegion.Bounds; scale = new Vector2(spriteComp.Bounds.X / sourceRectangle.Width, spriteComp.Bounds.Y / sourceRectangle.Height); origin = new Vector2(sourceRectangle.Width, sourceRectangle.Height) * HalfHalf; SpriteBatch.Draw(animationComp.Animations[animationComp.ActiveAnimationIndex].TextureRegion.Texture, position * FlipY, sourceRectangle, spriteComp.Color * spriteComp.Alpha, -rotation, origin, scale * transformScale, SpriteEffects.None, 0); } else { SpriteBatch.Draw(spriteComp.Texture, position * FlipY, spriteComp.Color * spriteComp.Alpha, -rotation, origin, scale * transformScale, SpriteEffects.None, 0); } } foreach (Entity entity in _fontEntities) { BitmapFontComponent fontComp = entity.GetComponent <BitmapFontComponent>(); if (fontComp.Hidden || (fontComp.RenderGroup & groupMask) == 0) { continue; } TransformComponent transformComp = entity.GetComponent <TransformComponent>(); BoundingRect boundRect = new BoundingRect(transformComp.Position.X - (fontComp.Font.MeasureString(fontComp.Content).Width *transformComp.Scale / 2), transformComp.Position.Y - (fontComp.Font.MeasureString(fontComp.Content).Height *transformComp.Scale / 2), fontComp.Font.MeasureString(fontComp.Content).Width *transformComp.Scale, fontComp.Font.MeasureString(fontComp.Content).Height *transformComp.Scale); if (!boundRect.Intersects(camera.BoundingRect) && CVars.Get <bool>("debug_show_render_culling")) { continue; } Vector2 position; float rotation; float transformScale; transformComp.Interpolate(betweenFrameAlpha, out position, out rotation, out transformScale); Vector2 origin = fontComp.Font.MeasureString(fontComp.Content) / 2; SpriteBatch.DrawString(fontComp.Font, fontComp.Content, position * FlipY, fontComp.Color, -rotation, origin, transformScale, SpriteEffects.None, 0); } SpriteBatch.End(); }