Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split the stencil's public getter from the private setter. #52

Merged
merged 1 commit into from
May 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions Sources/PlaydateKit/Core/Sprite.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,14 @@ public enum Sprite {
// MARK: Public

/// The sprite's stencil bitmap, if set.
public private(set) var stencil: Graphics.Bitmap?



// I don't know why previous public private(set) var stencil
// was causing this kind of error https://github.com/finnvoor/PlaydateKit/issues/51
// Separating the public getter from ste private storage, resolved the issue
private var _stencil: Graphics.Bitmap?
public var stencil: Graphics.Bitmap? { _stencil }

/// The bitmap currently assigned to the sprite.
public var image: Graphics.Bitmap? {
didSet {
Expand Down Expand Up @@ -203,7 +209,7 @@ public enum Sprite {
/// Specifies a stencil image to be set on the frame buffer before the sprite is drawn.
/// Pass `nil` to clear the sprite’s stencil.
public func setStencil(_ stencil: Graphics.Bitmap?) {
self.stencil = stencil
self._stencil = stencil
if let stencil {
sprite.setStencil.unsafelyUnwrapped(pointer, stencil.pointer)
} else {
Expand All @@ -214,14 +220,14 @@ public enum Sprite {
/// Specifies a stencil image to be set on the frame buffer before the sprite is drawn. If `tile` is set, the stencil will be tiled.
/// Tiled stencils must have width evenly divisible by 32.
public func setStencilImage(_ stencil: Graphics.Bitmap, tile: CInt) {
self.stencil = stencil
self._stencil = stencil
sprite.setStencilImage.unsafelyUnwrapped(pointer, stencil.pointer, tile)
}

/// Sets the sprite’s stencil to the given pattern.
public func setStencilPattern(_ pattern: UnsafeMutablePointer<UInt8>) {
sprite.setStencilPattern.unsafelyUnwrapped(pointer, pattern)
stencil = nil
_stencil = nil
}

/// Sets the clipping rectangle for sprite drawing.
Expand Down
Loading