![]() |
Gondwana Game Engine
Gondwana is a cross-platform 2.5D game and rendering engine written in C#/.NET 8. It provides fine-grained control over rendering, timing, and scene composition, with built-in support for parallax, z-ordering, pixel overhang, collision detection, and particle effects. Gondwana targets desktop, mobile, and web platforms using SkiaSharp for graphics and NAudio for sound.
|
Renders a bitmap or image to a rectangular region with support for scaling modes, source clipping, tinting, opacity, blend modes, and rotation. More...
Public Types | |
| enum | ScaleMode { Stretch , Fit , Fill , Center , PixelPerfect } |
| Defines how an image is scaled to fit within the destination rectangle. More... | |
| Public Types inherited from Gondwana.Drawing.Direct.DirectDrawingBase | |
| enum | RevealDirection { LeftToRight , RightToLeft , TopToBottom , BottomToTop } |
| Defines the direction from which a reveal animation progressively displays the direct drawing. More... | |
Public Member Functions | |
| DirectImage (SKBitmap bitmap, RenderSurfaceHostBase renderSurfaceHost, SceneLayer sceneLayer, Rectangle worldBounds, string? nickname=null) | |
| Initializes a new instance of the DirectImage class for scene-layer (world-space) rendering using a bitmap. | |
| DirectImage (SKBitmap bitmap, RenderSurfaceHostBase renderSurfaceHost, View view, Rectangle screenBounds, string? nickname=null) | |
| Initializes a new instance of the DirectImage class for view (screen-space) rendering using a bitmap. | |
| DirectImage (SKImage image, RenderSurfaceHostBase renderSurfaceHost, SceneLayer sceneLayer, Rectangle worldBounds, string? nickname=null) | |
| Initializes a new instance of the DirectImage class for scene-layer (world-space) rendering using a pre-encoded image. | |
| DirectImage (SKImage image, RenderSurfaceHostBase renderSurfaceHost, View view, Rectangle screenBounds, string? nickname=null) | |
| Initializes a new instance of the DirectImage class for view (screen-space) rendering using a pre-encoded image. | |
| DirectImage | SetBitmap (SKBitmap bitmap) |
| Replaces the backing bitmap with a new one. | |
| DirectImage | SetImage (SKImage image) |
| Replaces the backing image with a new one. | |
| DirectImage | SetSourceRect (SKRect? srcPixels) |
| Sets the source rectangle within the image to display, enabling sprite sheet support. | |
| DirectImage | SetScaleMode (ScaleMode mode) |
| Sets how the image is scaled to fit within the destination rectangle. | |
| DirectImage | SetTint (SKColor color) |
| Applies a color tint (multiplicative blend) to the image. | |
| DirectImage | ClearTint () |
| Removes any color tint, restoring the image's original colors. | |
| DirectImage | SetOpacity (byte alpha) |
| Sets the overall opacity (alpha transparency) of the image. | |
| DirectImage | SetBlendMode (SKBlendMode mode) |
| Sets the Skia blend mode used when compositing this image onto the backbuffer. | |
| DirectImage | SetFilterQuality (SKFilterQuality q) |
| Sets the filter quality used when scaling the image. | |
| DirectImage | SetRotation (float degrees) |
| Sets the rotation angle in degrees around the anchor point. | |
| DirectImage | SetAnchor (float ax, float ay) |
| Sets the rotation and scaling anchor point within the destination rectangle using normalized coordinates. | |
| Public Member Functions inherited from Gondwana.Drawing.Direct.DirectDrawingMovableBase | |
| Vector2 | GetPosition () |
| Gets the current position of this direct drawing in pixel coordinates. | |
| void | SetPosition (Vector2 p) |
| Sets the position of this direct drawing to the specified pixel coordinates. | |
| override void | Update (long tick) |
| Performs per-frame update logic, including fixed-timestep physics integration for movement. | |
| Public Member Functions inherited from Gondwana.Drawing.Direct.DirectDrawingBase | |
| RectangleF | GetDrawLocationScreen (View view) |
| Gets the screen-space drawing location for this direct drawing as seen from the specified view. | |
| void | Draw (BackbufferBase backbuffer, RectangleF destRectScreen) |
| Renders this direct drawing to the backbuffer at the specified screen location. | |
| DirectDrawingBase | SetOpacity (float opacity) |
| Instantly sets the opacity to the specified value without animation. | |
| DirectDrawingBase | FadeTo (float targetOpacity, float durationSec) |
| Initiates a smooth fade transition to the specified target opacity over the given duration. | |
| DirectDrawingBase | FadeIn (float durationSec) |
| Fades this direct drawing from its current opacity to fully opaque over the specified duration. | |
| DirectDrawingBase | FadeOut (float durationSec) |
| Fades this direct drawing from its current opacity to fully transparent over the specified duration. | |
| DirectDrawingBase | CancelFade () |
| Cancels any active fade transition, leaving the opacity at its current value. | |
| DirectDrawingBase | SetReveal (float t01) |
| Instantly sets the reveal progress to the specified value without animation. | |
| DirectDrawingBase | SetRevealDirection (RevealDirection dir) |
| Sets the direction from which the reveal animation progresses. | |
| DirectDrawingBase | RevealTo (float t01, float durationSec, Func< float, float >? easing=null) |
| Initiates a smooth reveal animation to the specified target progress over the given duration, optionally using a custom easing function. | |
| int | CompareTo (DirectDrawingBase? other) |
| Compares this direct drawing to another for sorting by ZOrder. | |
| void | Dispose () |
| Releases all resources used by this DirectDrawingBase instance. | |
| override bool | Equals (object? obj) |
| Determines whether the specified object is equal to the current direct drawing. | |
| override int | GetHashCode () |
| Returns a hash code for this direct drawing. | |
Protected Member Functions | |
| override void | OnDraw (BackbufferBase backbuffer, RectangleF destRectScreen) |
| Renders the image to the backbuffer with all configured transformations and effects applied. | |
| Protected Member Functions inherited from Gondwana.Drawing.Direct.DirectDrawingMovableBase | |
| DirectDrawingMovableBase (RenderSurfaceHostBase renderSurfaceHost, DirectDrawingMode mode, SceneLayer? sceneLayer, View? view, Rectangle? screenBounds, Rectangle? worldBounds, string? name=null) | |
| Initializes a new instance of the DirectDrawingMovableBase class with integrated movement capabilities. | |
| Protected Member Functions inherited from Gondwana.Drawing.Direct.DirectDrawingBase | |
| void | OnDraw (BackbufferBase backbuffer, RectangleF destRectScreen) |
| Performs the concrete drawing for this direct drawing to the backbuffer. | |
| DirectDrawingBase (RenderSurfaceHostBase renderSurfaceHost, DirectDrawingMode mode, SceneLayer? sceneLayer, View? view, Rectangle? screenBounds, Rectangle? worldBounds, string? nickname=null) | |
| Initializes a new instance of the DirectDrawingBase class. | |
| virtual void | Dispose (bool disposing) |
| Releases resources used by this DirectDrawingBase instance. | |
Additional Inherited Members | |
| Static Public Member Functions inherited from Gondwana.Drawing.Direct.DirectDrawingBase | |
| static bool | operator== (DirectDrawingBase? left, DirectDrawingBase? right) |
| Determines whether two direct drawing instances are equal using reference equality. | |
| static bool | operator!= (DirectDrawingBase? left, DirectDrawingBase? right) |
| Determines whether two direct drawing instances are not equal using reference equality. | |
| static bool | operator< (DirectDrawingBase? left, DirectDrawingBase? right) |
| Determines whether the Z-order of the left direct drawing is less than the right. | |
| static bool | operator<= (DirectDrawingBase? left, DirectDrawingBase? right) |
| Determines whether the Z-order of the left direct drawing is less than or equal to the right. | |
| static bool | operator> (DirectDrawingBase? left, DirectDrawingBase? right) |
| Determines whether the Z-order of the left direct drawing is greater than the right. | |
| static bool | operator>= (DirectDrawingBase? left, DirectDrawingBase? right) |
| Determines whether the Z-order of the left direct drawing is greater than or equal to the right. | |
| Protected Attributes inherited from Gondwana.Drawing.Direct.DirectDrawingBase | |
| readonly RenderSurfaceHostBase | _renderSurfaceHost |
| The render surface host that manages this direct drawing's rendering pipeline. | |
| Rectangle | _screenBounds |
| The current screen-space bounds for view-mode direct drawings, in pixels. | |
| Rectangle | _worldBounds |
| The current world-space bounds for scene-layer-mode direct drawings, in pixels. | |
| int | _zOrder |
| The Z-order used for draw sorting. Higher values draw later (on top). | |
| bool | _visible |
| Indicates whether this direct drawing is currently visible and should be rendered. | |
| long | _lastTick = HighResTimer.GetCurrentTick() |
| The last engine tick value used for delta-time calculations in Update. | |
| Properties inherited from Gondwana.Drawing.Direct.DirectDrawingMovableBase | |
| MovementController | Movement [get] |
| Gets the movement controller that manages physics-based position, velocity, and forces for this direct drawing. | |
| MovementSpace | PositionSpace [get] |
| Gets the coordinate space in which this movable object's position is expressed. | |
| Properties inherited from Gondwana.Drawing.Direct.DirectDrawingBase | |
| bool | HideWhenFullyTransparent = true [get, set] |
| Gets or sets a value indicating whether this direct drawing should be automatically hidden when its opacity reaches zero during fade transitions. | |
| RenderSurfaceHostBase | RenderSurfaceHost [get] |
| Gets the render surface host that manages this direct drawing's rendering pipeline. | |
| DirectDrawingMode | Mode [get] |
| Gets the drawing mode that determines how this direct drawing is positioned and transformed. | |
| SceneLayer? | SceneLayer [get] |
Gets the scene layer to which this direct drawing is attached, or null if the drawing is in view mode. | |
| View? | View [get] |
Gets the view to which this direct drawing is attached, or null if the drawing is in scene-layer mode. | |
| Rectangle | ScreenBounds [get, set] |
| Gets or sets the screen-space bounds of this direct drawing in pixels. | |
| Rectangle | WorldBounds [get, set] |
| Gets or sets the world-space bounds of this direct drawing in pixels. | |
| TypedValueBag | ValueBag = new() [get] |
| Gets the extensible value bag for storing arbitrary key-value data associated with this direct drawing. | |
| Guid | Id = Guid.NewGuid() [get] |
| Gets the unique identifier for this direct drawing. | |
| string? | Nickname [get] |
| Gets the optional human-readable name for this direct drawing. | |
| int | ZOrder [get, set] |
| Gets or sets the Z-order (depth) used for sorting this direct drawing relative to other drawables. | |
| bool | Visible [get, set] |
| Gets or sets a value indicating whether this direct drawing is visible and should be rendered. | |
| float | Opacity [get, set] |
| Gets or sets the current opacity of this direct drawing. | |
| Events inherited from Gondwana.Drawing.Direct.DirectDrawingBase | |
| EventHandler< IDirectDrawable >? | Disposing |
| Occurs when this direct drawing is being disposed. | |
| EventHandler< DirectDrawingBase >? | FadeToCompleted |
| Occurs when a fade transition initiated by FadeTo, FadeIn, or FadeOut completes. | |
| Events inherited from Gondwana.Drawing.Direct.IDirectDrawable | |
| EventHandler< IDirectDrawable >? | Disposing |
| Occurs when the object is being disposed. | |
Renders a bitmap or image to a rectangular region with support for scaling modes, source clipping, tinting, opacity, blend modes, and rotation.
DirectImage provides a flexible way to display images (either SKImage or SKBitmap) with extensive control over rendering appearance. It supports both world-space (scene-layer mode) and screen-space (view mode) positioning, making it suitable for both in-game sprites and UI elements.
Key features:
Important: DirectImage does not take ownership of the provided SKImage or SKBitmap. The caller is responsible for managing the lifetime of image resources and ensuring they remain valid while the DirectImage is in use. Dispose of image resources only after disposing the DirectImage.
All setter methods return this to enable fluent-style method chaining. Each setter automatically marks the affected screen regions as dirty to trigger rerendering on the next frame.
Thread safety: This class is not thread-safe. All operations should be performed on the UI thread.
Defines how an image is scaled to fit within the destination rectangle.
The scale mode determines the relationship between the source image dimensions and the destination rectangle, controlling whether the image is stretched, letterboxed, cropped, or displayed at native resolution.
| Gondwana.Drawing.Direct.DirectImage.DirectImage | ( | SKBitmap | bitmap, |
| RenderSurfaceHostBase | renderSurfaceHost, | ||
| SceneLayer | sceneLayer, | ||
| Rectangle | worldBounds, | ||
| string? | nickname = null ) |
Initializes a new instance of the DirectImage class for scene-layer (world-space) rendering using a bitmap.
| bitmap | The bitmap to display. Must not be null. The caller retains ownership and must manage its lifetime. |
| renderSurfaceHost | The render surface host that manages rendering for this image. Must not be null. |
| sceneLayer | The scene layer to which this image is attached. The image will be positioned in world coordinates relative to this layer. |
| worldBounds | The world-space bounds in pixels defining the image's position and size. |
| nickname | An optional human-readable name for this image, useful for debugging and identification. |
| ArgumentNullException | Thrown when bitmap or renderSurfaceHost is null. |
This constructor creates an image positioned in world coordinates that moves with the camera and is affected by the scene layer's parallax factor. Use this for in-game sprites, background elements, and other world-space visuals.
The bitmap is converted to SKImage during rendering for optimal performance. The caller must ensure the bitmap remains valid for the lifetime of this DirectImage instance.
| Gondwana.Drawing.Direct.DirectImage.DirectImage | ( | SKBitmap | bitmap, |
| RenderSurfaceHostBase | renderSurfaceHost, | ||
| View | view, | ||
| Rectangle | screenBounds, | ||
| string? | nickname = null ) |
Initializes a new instance of the DirectImage class for view (screen-space) rendering using a bitmap.
| bitmap | The bitmap to display. Must not be null. The caller retains ownership and must manage its lifetime. |
| renderSurfaceHost | The render surface host that manages rendering for this image. Must not be null. |
| view | The view to which this image is attached. The image will be positioned in screen coordinates relative to this view's viewport. |
| screenBounds | The screen-space bounds in pixels defining the image's position and size within the viewport. |
| nickname | An optional human-readable name for this image, useful for debugging and identification. |
| ArgumentNullException | Thrown when bitmap or renderSurfaceHost is null. |
This constructor creates an image positioned in screen coordinates that remains fixed on screen regardless of camera movement. Use this for UI elements, HUD overlays, menus, and other screen-space visuals.
The bitmap is converted to SKImage during rendering for optimal performance. The caller must ensure the bitmap remains valid for the lifetime of this DirectImage instance.
| Gondwana.Drawing.Direct.DirectImage.DirectImage | ( | SKImage | image, |
| RenderSurfaceHostBase | renderSurfaceHost, | ||
| SceneLayer | sceneLayer, | ||
| Rectangle | worldBounds, | ||
| string? | nickname = null ) |
Initializes a new instance of the DirectImage class for scene-layer (world-space) rendering using a pre-encoded image.
| image | The image to display. Must not be null. The caller retains ownership and must manage its lifetime. |
| renderSurfaceHost | The render surface host that manages rendering for this image. Must not be null. |
| sceneLayer | The scene layer to which this image is attached. The image will be positioned in world coordinates relative to this layer. |
| worldBounds | The world-space bounds in pixels defining the image's position and size. |
| nickname | An optional human-readable name for this image, useful for debugging and identification. |
| ArgumentNullException | Thrown when image or renderSurfaceHost is null. |
This constructor creates an image positioned in world coordinates that moves with the camera and is affected by the scene layer's parallax factor. Use this for in-game sprites, background elements, and other world-space visuals.
Using SKImage directly is more efficient than SKBitmap for rendering, especially when the same image is used multiple times. The caller must ensure the image remains valid for the lifetime of this DirectImage instance.
| Gondwana.Drawing.Direct.DirectImage.DirectImage | ( | SKImage | image, |
| RenderSurfaceHostBase | renderSurfaceHost, | ||
| View | view, | ||
| Rectangle | screenBounds, | ||
| string? | nickname = null ) |
Initializes a new instance of the DirectImage class for view (screen-space) rendering using a pre-encoded image.
| image | The image to display. Must not be null. The caller retains ownership and must manage its lifetime. |
| renderSurfaceHost | The render surface host that manages rendering for this image. Must not be null. |
| view | The view to which this image is attached. The image will be positioned in screen coordinates relative to this view's viewport. |
| screenBounds | The screen-space bounds in pixels defining the image's position and size within the viewport. |
| nickname | An optional human-readable name for this image, useful for debugging and identification. |
| ArgumentNullException | Thrown when image or renderSurfaceHost is null. |
This constructor creates an image positioned in screen coordinates that remains fixed on screen regardless of camera movement. Use this for UI elements, HUD overlays, menus, and other screen-space visuals.
Using SKImage directly is more efficient than SKBitmap for rendering, especially when the same image is used multiple times. The caller must ensure the image remains valid for the lifetime of this DirectImage instance.
| DirectImage Gondwana.Drawing.Direct.DirectImage.ClearTint | ( | ) |
Removes any color tint, restoring the image's original colors.
After calling this method, the image will be rendered with its original colors (equivalent to a white tint). Opacity settings from SetOpacity remain unaffected.
The affected screen regions are automatically marked as dirty to trigger rerendering on the next frame.
|
protected |
Renders the image to the backbuffer with all configured transformations and effects applied.
| backbuffer | The backbuffer providing the canvas and rendering context. |
| destRectScreen | The destination rectangle in screen pixel coordinates where the image should be rendered. |
This method is called automatically by the rendering pipeline. It performs the following operations:
Do not call this method directly from game code. To trigger a redraw, call DirectDrawingBase.ForceRefresh or modify properties that affect appearance.
| DirectImage Gondwana.Drawing.Direct.DirectImage.SetAnchor | ( | float | ax, |
| float | ay ) |
Sets the rotation and scaling anchor point within the destination rectangle using normalized coordinates.
| ax | The horizontal anchor position from 0.0 (left edge) to 1.0 (right edge). Values are clamped to this range. |
| ay | The vertical anchor position from 0.0 (top edge) to 1.0 (bottom edge). Values are clamped to this range. |
The anchor point determines the origin for rotation transformations. It is specified in normalized coordinates relative to the destination rectangle:
For example, setting the anchor to (1.0, 0.5) and rotating will cause the image to rotate around its right-center edge, creating a door-opening effect.
Values outside the 0..1 range are clamped. The affected screen regions are automatically marked as dirty to trigger rerendering on the next frame.
| DirectImage Gondwana.Drawing.Direct.DirectImage.SetBitmap | ( | SKBitmap | bitmap | ) |
Replaces the backing bitmap with a new one.
| bitmap | The new bitmap to display. Must not be null. |
| ArgumentNullException | Thrown when bitmap is null. |
This method replaces the current image source with the specified bitmap. The bitmap is converted to SKImage during rendering for optimal performance. Any previously set SKImage is discarded (but not disposed, as ownership remains with the caller).
The affected screen regions are automatically marked as dirty to trigger rerendering on the next frame. The caller retains ownership of the bitmap and must ensure it remains valid while in use.
| DirectImage Gondwana.Drawing.Direct.DirectImage.SetBlendMode | ( | SKBlendMode | mode | ) |
Sets the Skia blend mode used when compositing this image onto the backbuffer.
| mode | The blend mode to apply. See SKBlendMode for available options. |
The blend mode determines how the image's pixels are combined with the existing backbuffer contents. Common modes include:
The affected screen regions are automatically marked as dirty to trigger rerendering on the next frame.
| DirectImage Gondwana.Drawing.Direct.DirectImage.SetFilterQuality | ( | SKFilterQuality | q | ) |
Sets the filter quality used when scaling the image.
| q | The filter quality level. Higher quality produces smoother results but may be slower. See SKFilterQuality for available options. |
Filter quality affects how the image is sampled when scaling. Options include:
For pixel art games, use SKFilterQuality.None combined with ScaleMode.PixelPerfect to preserve crisp pixel boundaries.
The affected screen regions are automatically marked as dirty to trigger rerendering on the next frame.
| DirectImage Gondwana.Drawing.Direct.DirectImage.SetImage | ( | SKImage | image | ) |
Replaces the backing image with a new one.
| image | The new image to display. Must not be null. |
| ArgumentNullException | Thrown when image is null. |
This method replaces the current image source with the specified SKImage. Any previously set SKBitmap is discarded. Using SKImage directly is more efficient for rendering than converting from SKBitmap.
The affected screen regions are automatically marked as dirty to trigger rerendering on the next frame. The caller retains ownership of the image and must ensure it remains valid while in use.
| DirectImage Gondwana.Drawing.Direct.DirectImage.SetOpacity | ( | byte | alpha | ) |
Sets the overall opacity (alpha transparency) of the image.
| alpha | The opacity value from 0 (fully transparent) to 255 (fully opaque). |
The opacity is applied uniformly to the entire image after any tint has been applied. An opacity of 0 makes the image invisible, while 255 renders it at full opacity.
This opacity is independent of the DirectDrawingBase.Opacity property inherited from the base class. If both are set, their effects are combined multiplicatively during rendering.
The affected screen regions are automatically marked as dirty to trigger rerendering on the next frame.
| DirectImage Gondwana.Drawing.Direct.DirectImage.SetRotation | ( | float | degrees | ) |
Sets the rotation angle in degrees around the anchor point.
| degrees | The rotation angle in degrees. Positive values rotate clockwise, negative values rotate counter-clockwise. |
The image is rotated around the anchor point specified by SetAnchor. By default, the anchor is at the center (0.5, 0.5), so the image rotates around its center point.
A rotation of 0 degrees means no rotation. Values are not clamped; you can specify any angle, and it will wrap around (e.g., 360 degrees is equivalent to 0 degrees).
The affected screen regions are automatically marked as dirty to trigger rerendering on the next frame.
| DirectImage Gondwana.Drawing.Direct.DirectImage.SetScaleMode | ( | ScaleMode | mode | ) |
Sets how the image is scaled to fit within the destination rectangle.
| mode | The scaling mode to apply. See ScaleMode for available options. |
The scale mode determines how the source image (or source rectangle) is mapped to the destination bounds. Different modes preserve or ignore aspect ratio and handle size mismatches differently:
The affected screen regions are automatically marked as dirty to trigger rerendering on the next frame.
| DirectImage Gondwana.Drawing.Direct.DirectImage.SetSourceRect | ( | SKRect? | srcPixels | ) |
Sets the source rectangle within the image to display, enabling sprite sheet support.
| srcPixels | The source rectangle in image pixel coordinates, or null to display the entire image. Coordinates are relative to the top-left corner of the image. |
Use this method to display a specific region of a larger image, which is useful for sprite sheets, texture atlases, or animated sprites. When null, the entire image is displayed.
The source rectangle dimensions do not need to match the destination rectangle; the specified region will be scaled according to the current SetScaleMode.
The affected screen regions are automatically marked as dirty to trigger rerendering on the next frame.
| DirectImage Gondwana.Drawing.Direct.DirectImage.SetTint | ( | SKColor | color | ) |
Applies a color tint (multiplicative blend) to the image.
| color | The tint color to apply. Each RGB channel is multiplied with the corresponding image pixel channel. |
The tint color is multiplied with each pixel of the source image using SKBlendMode.Modulate. White (SKColors.White) produces no color change, while other colors shift the image's hue. Black will result in a completely black image.
The alpha channel of the tint color is ignored; use SetOpacity to control transparency. To remove the tint and restore original colors, call ClearTint.
The affected screen regions are automatically marked as dirty to trigger rerendering on the next frame.