-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStart.swift
More file actions
86 lines (77 loc) · 2.74 KB
/
Start.swift
File metadata and controls
86 lines (77 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
See the LICENSE.txt file for this sample’s licensing information.
Abstract:
The start screen for the game.
*/
import SwiftUI
import GroupActivities
struct Start: View {
@Environment(GameModel.self) var gameModel
@Environment(\.openImmersiveSpace) private var openImmersiveSpace
@StateObject private var groupStateObserver = GroupStateObserver()
var body: some View {
VStack(spacing: 10) {
Spacer()
Image("splashScreen")
.resizable()
.frame(width: 337, height: 211)
.accessibilityHidden(true)
Text("Happy Beam")
.font(.system(size: 30, weight: .bold))
Text("Cheer up grumpy clouds by shining a happy beam with your heart.")
.multilineTextAlignment(.center)
.font(.headline)
.frame(width: 340)
.padding(.bottom, 10)
if gameModel.readyToStart {
Group {
Button {
gameModel.isPlaying = true
gameModel.timeLeft = GameModel.gameTime
} label: {
Text("Play Solo")
.frame(maxWidth: .infinity)
}
.disabled(!gameModel.readyToStart)
Button {
print("Starting as SharePlay", groupStateObserver.isEligibleForGroupSession)
Task {
do {
try await startSession()
} catch {
print("SharePlay session failure", error)
}
}
} label: {
Text("Play with Friends")
.frame(maxWidth: .infinity)
}
.disabled(!groupStateObserver.isEligibleForGroupSession)
}
.font(.system(size: 16, weight: .bold))
.frame(width: 180)
} else {
ProgressView("Loading assets...")
}
Spacer()
}
.padding(.horizontal, 150)
.frame(width: 634, height: 499)
.onAppear {
gameModel.menuPlayer.volume = 0.6
gameModel.menuPlayer.numberOfLoops = -1
gameModel.menuPlayer.currentTime = 0
gameModel.menuPlayer.play()
}
}
}
#Preview {
Start()
.environment(GameModel())
.glassBackgroundEffect(
in: RoundedRectangle(
cornerRadius: 32,
style: .continuous
)
)
}