-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🏗 Integrates GameplayKit components with the SpriteKit scene editor
Closes #29
- Loading branch information
Showing
12 changed files
with
138 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// BlinkComponent.swift | ||
// SKTetris | ||
// | ||
// Created by Christophe SAUVEUR on 28/05/2021. | ||
// | ||
|
||
import GameplayKit | ||
|
||
class BlinkComponent: GKComponent { | ||
|
||
private let BLINK_TIME_INTERVAL = 0.1 | ||
private let MAX_BLINK_PHASE = 10 | ||
|
||
var blinking = false | ||
private var blinkTimeBuffer: TimeInterval = 0 | ||
private var blinkPhase = 0 | ||
|
||
override func update(deltaTime seconds: TimeInterval) { | ||
if blinking { | ||
blinkTimeBuffer += seconds | ||
while blinkTimeBuffer > BLINK_TIME_INTERVAL && blinkPhase < MAX_BLINK_PHASE { | ||
blinkTimeBuffer -= BLINK_TIME_INTERVAL | ||
blinkPhase = min(blinkPhase + 1, MAX_BLINK_PHASE) | ||
} | ||
|
||
guard let skNode = entity?.component(ofType: GKSKNodeComponent.self)?.node else { | ||
return | ||
} | ||
|
||
if blinkPhase % 2 == 1 { | ||
skNode.alpha = 0.5 | ||
} | ||
else { | ||
skNode.alpha = 1 | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.