I am trying to use an EnvironmentObject in an init. I am aware that this is not possible because it hasn't been initialised yet.
But what is the solution? I have tried loading the scene.gameCenterManger in .onAppear but that doesn't seem to work.
I want to use @State for my gamescene variable, because SKScene will reset itself when the view does a refresh.
struct GameSceneView: View {
@EnvironmentObject var gameCenterManager:GameCenterManager
@State var scene = GameScene()
init() {
scene.size = CGSize(width: 1000, height: 1800)
scene.scaleMode = .aspectFill
// doing it as below will throw an error.
//scene.gameCenterManager = gameCenterManager
}
var body: some View {
SpriteView(scene: scene )
.environmentObject(gameCenterManager)
.frame(width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height)
.ignoresSafeArea()
.overlay(ImageOverlay(), alignment: .bottomTrailing)
.onAppear{ scene.gameCenterManager = gameCenterManager }
}
}
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
How do I get the visible screen area dimensions of SKScene while using Spriteview?
I used to do :
let bottomLeft = convertPoint(fromView: .zero)
But when I do that now I get nan, nan
I read about GeometryReader, because its SwiftUI casting a SKScene (lack for better wording). So I should be able to get the needed information out of GeometryReader. But have no idea how.
What I basically need is information on what pixel the SKScene actually starts on bottom left, and where it ends top right. Due to aspect ratios this can vary on different screens, iPad, iPhone etc.
I am trying to implement GameKit in SwiftUI using iOS 14.5.
I can connect and retrieve leaderboard on a real physical iPhone and on the simulator. However when I try to connect using GKMatchRequest from physical iPhone to the simulator I get an error. There are no issues when I try to connect from physical to physical phone. Is this a known issue? Is there something I should do that I am not aware of? The odd part is that, as said, physical to physical works fine.
Domain=GKErrorDomain Code=3 "The requested operation could not be completed due to an error communicating with the server." UserInfo={GKServerStatusCode=5030
The requested operation could not be completed due to an error communicating with the server., NSUnderlyingError=0x281bb8db0
No registration for peer
thanks in advance