Gondwana Game Engine Development (master) - 2.7.0
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(
55 Tilesheet tilesheet,
56 string regionName,
57 int xTile,
58 int yTile)
59 {
60 Tilesheet = tilesheet;
61 RegionName = regionName;
62 XTile = xTile;
63 YTile = yTile;
64 }
65
69 public readonly SKBitmap? SkBitmap => Tilesheet?.GetBitmap(RegionName, XTile, YTile);
70
74 public readonly SKImage? SkImage => Tilesheet?.GetImage(RegionName, XTile, YTile);
75
76 internal readonly SKImage? AtlasImage => Tilesheet?.AtlasImage;
77
78 internal readonly Rectangle AtlasSourceBounds =>
79 Tilesheet?.GetRegion(RegionName)?.GetFrameSourceBounds(XTile, YTile)
80 ?? Rectangle.Empty;
81
85 public readonly Size TileSize => Tilesheet?.GetRegion(RegionName)?.TileSize ?? Size.Empty;
86
90 public readonly Spacing Overhang => Tilesheet?.GetRegion(RegionName)?.Overhang ?? Spacing.None;
91
93 public readonly Spacing TilePadding => Tilesheet?.GetRegion(RegionName)?.TilePadding ?? Spacing.None;
94
103 {
104 readonly get => Tilesheet?.GetRegion(RegionName)?.GetFrameCollisionAdjust(XTile, YTile)
106 set
107 {
108 var region = Tilesheet?.GetRegion(RegionName)
109 ?? throw new InvalidOperationException(
110 $"Tilesheet region '{RegionName}' could not be resolved for this frame.");
111
112 region.SetFrameCollisionAdjust(XTile, YTile, value);
113 }
114 }
115
120 public readonly bool HasCollisionAdjustOverride =>
121 Tilesheet?.GetRegion(RegionName)?.TryGetFrameCollisionAdjustOverride(
122 XTile,
123 YTile,
124 out _) == true;
125
131 public readonly bool ClearCollisionAdjustOverride()
132 {
133 var region = Tilesheet?.GetRegion(RegionName)
134 ?? throw new InvalidOperationException(
135 $"Tilesheet region '{RegionName}' could not be resolved for this frame.");
136
137 return region.ClearFrameCollisionAdjustOverride(XTile, YTile);
138 }
139
144 public readonly Rectangle CollisionArea => CollisionAdjust.ApplyTo(new Rectangle(Point.Empty, TileSize));
145
151 {
152 readonly get => Tilesheet?.GetRegion(RegionName)?.GetFrameCollisionType(XTile, YTile)
153 ?? TileCollisionType.None;
154 set
155 {
156 var region = Tilesheet?.GetRegion(RegionName)
157 ?? throw new InvalidOperationException(
158 $"Tilesheet region '{RegionName}' could not be resolved for this frame.");
159
160 region.SetFrameCollisionType(XTile, YTile, value);
161 }
162 }
163
168 public readonly bool HasCollisionTypeOverride =>
169 Tilesheet?.GetRegion(RegionName)?.TryGetFrameCollisionTypeOverride(
170 XTile,
171 YTile,
172 out _) == true;
173
179 public readonly bool ClearCollisionTypeOverride()
180 {
181 var region = Tilesheet?.GetRegion(RegionName)
182 ?? throw new InvalidOperationException(
183 $"Tilesheet region '{RegionName}' could not be resolved for this frame.");
184
185 return region.ClearFrameCollisionTypeOverride(XTile, YTile);
186 }
187}
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:69
readonly bool ClearCollisionTypeOverride()
Removes this frame's explicit collision type so it once again inherits its region's TilesheetRegion....
Definition Frame.cs:179
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:131
readonly Spacing TilePadding
Gets untransformed source atlas padding; placement transforms never alter slicing.
Definition Frame.cs:93
readonly bool HasCollisionTypeOverride
Gets whether this frame has an explicit collision type rather than inheriting its region's TilesheetR...
Definition Frame.cs:168
readonly Rectangle CollisionArea
Gets the frame-local collision rectangle derived from TileSize and CollisionAdjust.
Definition Frame.cs:144
CollisionAdjust CollisionAdjust
Gets or sets the collision adjustment associated with this frame's region coordinates.
Definition Frame.cs:103
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:74
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:120
TileCollisionType CollisionType
Gets or sets the effective collision type associated with this frame's region coordinates.
Definition Frame.cs:151
readonly Size TileSize
Gets the base tile size, without overhang.
Definition Frame.cs:85
readonly Spacing Overhang
Gets the overhang dimensions for this frame.
Definition Frame.cs:90
Per-edge inset amounts applied to visual bounds to produce a collision rectangle.
static readonly CollisionAdjust None
Represents an adjustment with no pixel offsets.