@ -31,6 +31,8 @@ namespace DotSDL.Graphics {
private float _ nextGameUpdate ;
private float _ updateDelta ;
private List < Canvas > _d rawList = new List < Canvas > ( ) ;
private ScalingQuality _ scalingQuality = ScalingQuality . Nearest ;
/// <summary>
@ -228,6 +230,7 @@ namespace DotSDL.Graphics {
BlendMode = BlendMode . None
}
} ;
Background . ZOrder = int . MinValue ;
Background . CreateTexture ( ) ;
CameraView = new Rectangle (
@ -277,8 +280,17 @@ namespace DotSDL.Graphics {
Render . SetRenderTarget ( _ renderer , _ texture ) ;
// Blit the background canvases to the target texture.
foreach ( var canvas in Layers ) {
// Sort all of the canvases, then draw them.
_d rawList . Clear ( ) ;
_d rawList . AddRange ( Layers . Where ( l = > l . Shown ) . ToArray ( ) ) ;
_d rawList . AddRange ( Sprites . Where ( s = > s . Shown ) . ToArray ( ) ) ;
foreach ( var canvas in _d rawList . OrderBy ( layer = > layer . ZOrder ) ) {
switch ( canvas ) {
case Sprite sprite :
DrawSprite ( sprite ) ;
break ;
default :
canvas . Clipping . Position = CameraView . Position ;
canvas . Clipping . Size = CameraView . Size ;
canvas . UpdateTexture ( ) ;
@ -286,10 +298,10 @@ namespace DotSDL.Graphics {
var canvasClippingRect = canvas . Clipping . SdlRect ;
Render . RenderCopy ( _ renderer , canvas . Texture , new IntPtr ( & canvasClippingRect ) , IntPtr . Zero ) ;
}
}
// Plot sprites on top of the background layer.
if ( Sprites . Count > 0 ) DrawSprites ( ) ;
break ;
}
}
Render . SetRenderTarget ( _ renderer , IntPtr . Zero ) ;
Render . RenderCopy ( _ renderer , _ texture , IntPtr . Zero , IntPtr . Zero ) ;
@ -343,13 +355,11 @@ namespace DotSDL.Graphics {
}
/// <summary>
/// Plots the sprites stored in <see cref="Sprites"/> to the screen. Please note that this method is called by
/// DotSDL's drawing routines and does not need to be called manually. Additionally, this method will not be
/// called if there are no sprites defined . You usually do not need to override this method.
/// Plots a sprite to the screen. Please note that this method is called by DotSDL's drawing
/// routines and does not need to be called manually. Additionally, this method will never be
/// called if there are no active sprites. You usually do not need to override this method.
/// </summary>
public virtual void DrawSprites ( ) {
Render . SetRenderTarget ( _ renderer , _ texture ) ;
foreach ( var sprite in Sprites . Where ( e = > e . Shown ) . OrderBy ( e = > e . ZOrder ) ) {
public virtual void DrawSprite ( Sprite sprite ) {
var srcRect = sprite . Clipping . SdlRect ;
var drawSize = sprite . DrawSize ;
@ -399,7 +409,6 @@ namespace DotSDL.Graphics {
) ;
}
}
}
/// <summary>
/// Retrieves the SDL resource ID for this <see cref="SdlWindow"/>.
@ -537,17 +546,13 @@ namespace DotSDL.Graphics {
/// <summary>
/// Displays the window and begins executing code that's associated with it.
/// </summary>
public void Start ( ) {
Start ( 0 , 0 ) ;
}
public void Start ( ) = > Start ( 0 , 0 ) ;
/// <summary>
/// Displays the window and begins executing code that's associated with it.
/// </summary>
/// <param name="updateRate">The desired number of video and game logic updates per second. 0 causes the display and game to be updated as quickly as possible.</param>
public void Start ( float updateRate ) {
Start ( updateRate , updateRate ) ;
}
public void Start ( float updateRate ) = > Start ( updateRate , updateRate ) ;
/// <summary>
/// Displays the window and begins executing code that's associated with it.