Post

Replies

Boosts

Views

Activity

How to use EnvironmentObject in an init()
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  }     } }
0
0
620
Aug ’21
How to get SKScene screen dimensions when using SpriteView
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.
2
0
693
Jul ’21
Cant connect to IOS 14 simulator using GKMatchRequest
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
0
0
540
Jul ’21
IOS GAME KIT observe GKInvite
This question is somewhat related to : https://developer.apple.com/forums/thread/652404 There seems no way to observe for incoming invitations in Game Kit, so I am looking for alternatives. Perhaps one alternative is adding an observer to GKInvite? Is this at all possible, and if so how do I create one? I am trying : GKInvite().addObserver(GKInvite(), forKeyPath: GKInvite().sender , options: .initial, context: GKPlayer) and GKInvite().observe( \GKInvite.sender , options: .initial){ person, change in 										print ( "SMTH CHANGED", person, change ) 								} The last one gives me a warning : Result of call to 'observe(_:options:changeHandler:)' is unused But perhaps someone here knows if it is at all possible and if so, how? GKInvite is an NSObject, and from what I have learned so far, its possible to observer for changes in an NSObject. Thanks in advance
0
0
368
Jul ’20
Where do I find pending invitations? GKInvite
Hi all, As many others inhere I am trying to figure out how gamekit works. At the moment I am able to invite a friend and accept it. But what I am not able to do is to fetch pending invites, if the player missed the notification how can I present missed invitations to the player? Assuming the other side will wait of course to get connected. User 1 > sends invite to User 2 User 2 > was too late and missed the notification User 1 > still waiting for User 2 to accept User 2 > can't find the pending invitation anywhere what I have so far:     func player(_ player: GKPlayer, didAccept invite: GKInvite) {         pendingInvite = invite         print("invite = \(invite)")         GKMatchmaker.shared().match (for: invite, completionHandler: {             (InvitedMatch, error) in             if error != nil {                 if let description = error?.localizedDescription {                     print("Error creating match from invitation: \(description)")                 }             } else {                 print ( "NO ERROR")                 self.update(with: InvitedMatch)             }         })     }     func update(with match: GKMatch?) {         self.multiplayerMatch = match         self.multiplayerMatch?.delegate = self         if !multiplayerMatchStarted && multiplayerMatch?.expectedPlayerCount == 0 {             print ("Ready to start the match MatchMaker")             delegate?.matchStarted()         } else {             print ("no players")         }     }
1
0
773
Jun ’20