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

Subclass Sprite #2

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
--swiftversion 6
--enable blankLineAfterImports
--enable blankLinesBetweenImports
--enable blockComments
Expand Down
28 changes: 23 additions & 5 deletions Sources/PlaydateKitTemplate/Game.swift
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import PlaydateKit

// MARK: - Game

final class Game: PlaydateGame {
// MARK: Lifecycle

init() {
logoSprite.image = try! Graphics.Bitmap(path: "logo.png")
logoSprite.bounds = .init(x: 0, y: 0, width: 400, height: 240)
logoSprite.addToDisplayList()
logo.addToDisplayList()
}

// MARK: Internal

let logoSprite = Sprite.Sprite()
let logo = Logo()

func update() -> Bool {
Sprite.drawDisplayListSprites()
Sprite.updateAndDrawDisplayListSprites()
System.drawFPS()
return true
}
Expand All @@ -23,3 +23,21 @@ final class Game: PlaydateGame {
System.log("Paused!")
}
}

// MARK: - Logo

class Logo: Sprite.Sprite {
// MARK: Lifecycle

override init() {
super.init()
image = try! Graphics.Bitmap(path: "logo.png")
bounds = .init(x: 0, y: 0, width: 400, height: 240)
}

// MARK: Internal

override func update() {
moveBy(dx: 0, dy: sinf(System.elapsedTime * 4))
}
}