Skip to content

Commit

Permalink
Split the stencil public getter from the private setter (#52)
Browse files Browse the repository at this point in the history
Co-authored-by: Eugenio Baglieri <eugenio.baglieri@skylabs.it>
  • Loading branch information
eugeniobaglieri and EBaglieriSkylabs authored May 5, 2024
1 parent 6f53ea9 commit 90e9f22
Showing 1 changed file with 11 additions and 5 deletions.
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

0 comments on commit 90e9f22

Please sign in to comment.