Gondwana Game Engine Development (master) - 2.6.1
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 and web platforms using SkiaSharp for graphics and pluggable audio backends for desktop and browser targets.
Loading...
Searching...
No Matches
Frame.cs
1using System.Drawing;
4using SkiaSharp;
5
6namespace Gondwana.Drawing;
7
11public struct Frame
12{
16 public readonly Tilesheet Tilesheet;
17
21 public readonly string RegionName;
22
26 public readonly int XTile;
27
31 public readonly int YTile;
32
39 public Frame(Tilesheet tilesheet, int xTile, int yTile)
40 {
41 Tilesheet = tilesheet;
43 XTile = xTile;
44 YTile = yTile;
45 }
46
54 public Frame(Tilesheet tilesheet, string regionName, int xTile, int yTile)
55 {
56 Tilesheet = tilesheet;
57 RegionName = regionName;
58 XTile = xTile;
59 YTile = yTile;
60 }
61
65 public readonly SKBitmap? SkBitmap => Tilesheet?.GetBitmap(RegionName, XTile, YTile);
66
70 public readonly SKImage? SkImage => Tilesheet?.GetImage(RegionName, XTile, YTile);
71
72 internal readonly SKImage? AtlasImage => Tilesheet?.AtlasImage;
73
74 internal readonly Rectangle AtlasSourceBounds =>
75 Tilesheet?.GetRegion(RegionName)?.GetFrameSourceBounds(XTile, YTile)
76 ?? Rectangle.Empty;
77
81 public readonly Size TileSize => Tilesheet?.GetRegion(RegionName)?.TileSize ?? Size.Empty;
82
86 public readonly Spacing Overhang => Tilesheet?.GetRegion(RegionName)?.Overhang ?? Spacing.None;
87
89 public readonly Spacing TilePadding => Tilesheet?.GetRegion(RegionName)?.TilePadding ?? Spacing.None;
90
99 {
100 readonly get => Tilesheet?.GetRegion(RegionName)?.GetFrameCollisionAdjust(XTile, YTile)
102 set
103 {
104 var region = Tilesheet?.GetRegion(RegionName)
105 ?? throw new InvalidOperationException(
106 $"Tilesheet region '{RegionName}' could not be resolved for this frame.");
107
108 region.SetFrameCollisionAdjust(XTile, YTile, value);
109 }
110 }
111
116 public readonly bool HasCollisionAdjustOverride =>
117 Tilesheet?.GetRegion(RegionName)?.TryGetFrameCollisionAdjustOverride(
118 XTile,
119 YTile,
120 out _) == true;
121
127 public readonly bool ClearCollisionAdjustOverride()
128 {
129 var region = Tilesheet?.GetRegion(RegionName)
130 ?? throw new InvalidOperationException(
131 $"Tilesheet region '{RegionName}' could not be resolved for this frame.");
132
133 return region.ClearFrameCollisionAdjustOverride(XTile, YTile);
134 }
135
140 public readonly Rectangle CollisionArea => CollisionAdjust.ApplyTo(new Rectangle(Point.Empty, TileSize));
141
147 {
148 readonly get => Tilesheet?.GetRegion(RegionName)?.GetFrameCollisionType(XTile, YTile)
149 ?? TileCollisionType.None;
150 set
151 {
152 var region = Tilesheet?.GetRegion(RegionName)
153 ?? throw new InvalidOperationException(
154 $"Tilesheet region '{RegionName}' could not be resolved for this frame.");
155
156 region.SetFrameCollisionType(XTile, YTile, value);
157 }
158 }
159
164 public readonly bool HasCollisionTypeOverride =>
165 Tilesheet?.GetRegion(RegionName)?.TryGetFrameCollisionTypeOverride(
166 XTile,
167 YTile,
168 out _) == true;
169
175 public readonly bool ClearCollisionTypeOverride()
176 {
177 var region = Tilesheet?.GetRegion(RegionName)
178 ?? throw new InvalidOperationException(
179 $"Tilesheet region '{RegionName}' could not be resolved for this frame.");
180
181 return region.ClearFrameCollisionTypeOverride(XTile, YTile);
182 }
183}
Represents a rectangular region within a tilesheet that contains a grid of frames.
static readonly string DefaultRegionName
The default name assigned to tilesheet regions when no name is specified.
record struct Spacing([property:JsonProperty("left")] int Left, [property:JsonProperty("top")] int Top, [property:JsonProperty("right")] int Right, [property:JsonProperty("bottom")] int Bottom)
Represents dimensions in pixels when spacing Tilesheets.
Definition Spacing.cs:12
TileCollisionType
Defines the default collision behavior associated with a tilesheet region, frame, or runtime tile.
readonly? SKBitmap SkBitmap
Gets the SkiaSharp bitmap for this frame.
Definition Frame.cs:65
readonly bool ClearCollisionTypeOverride()
Removes this frame's explicit collision type so it once again inherits its region's TilesheetRegion....
Definition Frame.cs:175
Frame(Tilesheet tilesheet, string regionName, int xTile, int yTile)
Initializes a new instance of the Frame struct with the specified tilesheet and tile coordinates.
Definition Frame.cs:54
readonly bool ClearCollisionAdjustOverride()
Removes this frame's explicit collision adjustment so it once again inherits its region's TilesheetRe...
Definition Frame.cs:127
readonly Spacing TilePadding
Gets untransformed source atlas padding; placement transforms never alter slicing.
Definition Frame.cs:89
readonly bool HasCollisionTypeOverride
Gets whether this frame has an explicit collision type rather than inheriting its region's TilesheetR...
Definition Frame.cs:164
readonly Rectangle CollisionArea
Gets the frame-local collision rectangle derived from TileSize and CollisionAdjust.
Definition Frame.cs:140
CollisionAdjust CollisionAdjust
Gets or sets the collision adjustment associated with this frame's region coordinates.
Definition Frame.cs:99
readonly int YTile
The vertical tile coordinate (row index) within the tilesheet.
Definition Frame.cs:31
readonly Tilesheet Tilesheet
The tilesheet that contains the source bitmap for this frame.
Definition Frame.cs:16
readonly string RegionName
The tilesheet region that contains the source bitmap for this frame.
Definition Frame.cs:21
readonly int XTile
The horizontal tile coordinate (column index) within the tilesheet.
Definition Frame.cs:26
readonly? SKImage SkImage
Gets the SkiaSharp image for this frame.
Definition Frame.cs:70
Frame(Tilesheet tilesheet, int xTile, int yTile)
Initializes a new instance of the Frame struct with the specified tilesheet and tile coordinates.
Definition Frame.cs:39
readonly bool HasCollisionAdjustOverride
Gets whether this frame has an explicit collision adjustment rather than inheriting its region's Tile...
Definition Frame.cs:116
TileCollisionType CollisionType
Gets or sets the effective collision type associated with this frame's region coordinates.
Definition Frame.cs:147
readonly Size TileSize
Gets the base tile size, without overhang.
Definition Frame.cs:81
readonly Spacing Overhang
Gets the overhang dimensions for this frame.
Definition Frame.cs:86
Per-edge inset amounts applied to visual bounds to produce a collision rectangle.
static readonly CollisionAdjust None
Represents an adjustment with no pixel offsets.