Post

Replies

Boosts

Views

Activity

Reply to How to detect the location of a mouseDown event using Swift?
(1) an iOS App (2) Someone else nailed it when he effectively stated that I called an iOS App with a macOS func mouseDown(with event: NSEvent). Actually, func mouseDown(with event: UIEvent) doesn't exist. iOS Apps deal with touches, not mouse clicks, obviously (3) I've got touches covered with override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {...} (4) BUT, I am hung up with how do I see if my code works with touches within Xcode? (5) Folk have their mouse linked to their iPad via Bluetooth ?
Topic: UI Frameworks SubTopic: AppKit Tags:
Feb ’24
Reply to How to detect the location of a mouseDown event using Swift?
I think I need to re-group and start from scratch ... I am so, so sorry: FWIW, your corrections are "spot on" if I were dealing with a macOS App, but I have a iOS App: How to detect the location of a mouseDown event using Swift? With the following code snippet, I get the error "Value of type 'UIEvent' has no member 'location' in scope"? import SpriteKit extension GameViewController { func mouseDown(with event: UIEvent) { if let ourScene = GameScene(fileNamed: "GameScene") { // error here: let location = event.location(in: view) let node:SKNode = ourScene.atPoint(location) if (node.name == "creditsInfo") { showCredits() } } // if let ourScene } // mouseDown } Anybody have a floodlight to shine on this very basic error?
Topic: UI Frameworks SubTopic: AppKit Tags:
Feb ’24
Reply to How to integrate UIDevice rotation and creating a new UIBezierPath after rotation?
In view of the fact that "something is better than nothing", I have decided (with rotation and the Train is moving) to: (1) stop the movement (2) delete the trackPath via func deletePath(_ thePath:UIBezierPath) { var thePoints = thePath.cgPath.getPoints() thePoints.removeAll() } // deletePath FWIW, getPoints() is an extension CGPath that I found elsewhere. (3) call createTrainPath() which starts the new UIBezierPath from the original starting point (4) finally call resumeGame() which calls startFollowTrainPath() It is 100% absolutely certain that this is much less than I desire which is to replace (3) with a new UIBezierPath which starts where the Train was before I rotated the UIDevice So, that challenge is still on the table ... In the meantime, I need to attack the very, very last challenge which is summarized here: https://stackoverflow.com/questions/77903234/why-does-orient-path-true-cause-the-sprite-node-to-rotate-cw-when-the-path-is I reference stack overflow.com because they allow presenting .pngs in an effort to show what the problem is all about. John Love
Topic: Graphics & Games SubTopic: General Tags:
Feb ’24
Reply to How to integrate UIDevice rotation and creating a new UIBezierPath after rotation?
TO: Albert from DTS .. You have acknowledged receipt of my complete bare bones Project. You keep asking for a simple Project, but I can honestly say that the Project you've received is bare bones and simple. I have led you step-by-step through (1) loading of my SKSpriteNodes, (2) running the Train with a Game Controller and (3) while the Train is moving, using Xcode to rotate the SKScene. Following this 3 step process, I see how, for example, If I am looking at Portrait mode, I see the moving Train following the old Landscape path. Like, while staring at Portrait mode, the Train disappears off the left edge and right edge of the UIDevice. = the OLD path In conclusion, I must very, very regretfully conclude that I must seek help elsewhere. Bye.
Topic: Graphics & Games SubTopic: General Tags:
Feb ’24
Reply to How to integrate UIDevice rotation and creating a new UIBezierPath after rotation?
Whoops ... you have to use a Game Controller to run the App FWIW - this eventual App actually will never be finished. I will always be expanding it, for example: (1) a track winding thru all sorts of hills (2) an animated waterfall (3) a hero galloping on a horse to rescue a damsel in distress There'll be a version 1.1, 1.2, 1.3 etc. I'm retired military and with the short term assignments (2 years between moving to somewhere else), I couldn't afford the time to set up an HO Train Set in my basement. So, this is the next best thing.
Topic: Graphics & Games SubTopic: General Tags:
Feb ’24
Reply to How to integrate UIDevice rotation and creating a new UIBezierPath after rotation?
Reference my comment above: I have even tried to delete the current UIBezierPath by calling trainPath.cgPath.getPoints().removeAll and then re-create it when the UIDevice is rotated. Once again, visually it shows that the SKSpriteNode follows the old UIBezierPath Next: if let ourScene = GameScene(fileNamed: thisSceneName) { // Force SKScene to fill up its parent SKView: if (thisSceneName == "GameScene") { ourScene.scaleMode = .aspectFill } else { ourScene.scaleMode = .resizeFill } } My rotation code is within: override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() if (thisSceneName == "GameScene") { setGamePieceParms() // for GamePieces, e.g., trainWidth + dogWidth setTrackPaths() // for trainPath + dogPath, etc. reSizeAndPositionNodes() } // if (thisSceneName == "GameScene") } // viewDidLayoutSubviews I chose it over: #if os(iOS) && !targetEnvironment(macCatalyst) NotificationCenter.default.addObserver(self, selector: #selector(rotated), name: UIDevice.orientationDidChangeNotification, object: nil) #endif @objc func rotated() { if (thisSceneName == "GameScene") { setGamePieceParms() // for GamePieces, e.g., trainWidth + dogWidth setTrackPaths() // for trainPath + dogPath, etc. reSizeAndPositionNodes() } // if (thisSceneName == "GameScene") } // rotated Anyway, I've got a complete focused Project as .zip, so how do I get it to you since you've chosen to reply within this Forum?
Topic: Graphics & Games SubTopic: General Tags:
Feb ’24
Reply to How to integrate UIDevice rotation and creating a new UIBezierPath after rotation?
After rotation, a new one has not been created. This is for certain because the SKSpriteNode follows the old one if it's moving before rotation. However, if I stop the movement before the rotation within viewDidLayoutSubviews() and resume the movement after the rotation, a new UIBezierPath is created. But what I want is to replace the UIBezierPath while moving when rotation happens. If you scroll up my OP, you will see that my viewDidLayoutSubviews() calls createTrainPath() which needs ? to be called during this rotation. As already noted, I have tried to effectively delete the old UIBezierPath by removing all the .cgPath [CGPoint] before calling setTrackPaths() (instead of stopping the movement and then resuming). Please note that my setTrackPaths() calls createTrainPath(). Unfortunately, the old Path stuck around with its old [CGPoint] and was never replaced by createTrainPath() when the latter called trainPath = UIBezierPath(ovalIn: trackRect). It just dawned on me that the problem could rest with my call to trackRect = CGRect(x:, y:, width:tracksWidth, height:tracksHeight). I say that because with rotation, the width and height parts change. Never mind ... I just deleted that guess because my call to setGamePieceParms() occurs before setTrackPaths() .. and the former changes tracksWidth and tracksHeight. Back to the drawing board ...
Topic: Graphics & Games SubTopic: General Tags:
Feb ’24
Reply to How to prevent initial rotation of a node when following a UIBezierPath?
From: Apple Developer Support ... I believe you can achieve what you are aiming for by using a "pivot" node. Effectively, you would add your "myTrain" node as a child of the "pivot". Then you would run the "trainAction" on the "pivot" instead of "myTrain". This allows "myTrain" to maintain its local zRotation relative to the path, but still follow the path. == It’s seemingly funny how things work out .. I was very recently asked who my favorite college prof was and why. I responded “Dr. Leno Pedrotti who taught Quantum Mechanics in Grad School. The reason I choose him as my favorite is because he was consistently able to reduce the extraordinarily convoluted subject to the simple, using simple and short statements in the process.” The above writer from Apple Developer Support was made from the same mold as Dr. Pedrotti. FWIW, we’re talking circa 1963 in case you “youngsters” are curious. To continue, here is my code wherein I “attempted” to implement the above writer’s concise solution: func moveTrainForward() { // trackPath + myTrain = globals let forwardTrackPath = trackPath let trainAction = SKAction.follow( forwardTrackPath!.cgPath, asOffset: false, orientToPath: true, duration: 0.1) createPivotNode(forSpriteNode: myTrain) myTrain.run(trainAction) } // moveTrainForward And here is the key createPivotNode: func createPivotNode(forSpriteNode: SKSpriteNode) { let nodeGeometry = SCNBox(width: forSpriteNode.size.width, height: 1, length: forSpriteNode.size.height, chamferRadius: 0) let theSCNNode = SCNNode(geometry: nodeGeometry) // create "pivot" node theSCNNode.pivot = SCNMatrix4MakeTranslation(0.5, 0.5, 0.5) if let ourSceneNode = SCNScene(named: "GameScene") { // effectively add "myTrain" node as a child of the "pivot" ??? ourSceneNode.rootNode.addChildNode(theSCNNode) } } // createPivotNode Unfortunately, the above does not prevent the rotation mentioned in my OP. I don't know for certain, but I think the core of this not working rests with my comment effectively add "myTrain" node as a child of the "pivot" ??? In conclusion, I need some further elaboration from my college prof.
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’24
Reply to UIBezierPath *not* showing?
It is totally clear to me that I am in a total fog ... When I set up my GameScene.sks within Xcode, I produced this: which I set as 1366 x 1366 The frame: designation below is in line with the anchor setting .. so the fog continues as to why the blue UIBezierPath is not showing // print("ourScene = \(ourScene)") // ourScene = <SKScene> name:'GameScene' // frame:{{-683, -683}, {1366, 1366}} // anchor:{0.5, 0.5}
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’23
Reply to UIBezierPath *not* showing?
Once again, my head got confused between: tracksPosY = roomPosY - roomHeight/2 + tracksHeight/2 where the .position is negative below the (0, 0) = center of the Scene and positive above (0, 0) With this UIBezierPath, the top of the CGRect is positive below the (0, 0) as exhibited by these data: // (l,t,r,b) // trackRect = (0.0, 207.0, 1024.0, 476.0) // portrait // trackRect = (0.0, 36.0, 1366.0, 476.0) // landscape // trackRect = (0.0, 64.0, 1920.0, 476.0) // osTV The bad news is that I still don't see a blue line anywhere. Given that, I am still doing something insanely wrong. I'm beginning to think my problem is with this statement: theTrackShapeNode.position = myTracks.position This is seriously suspect only because of the above-mentioned flip-flop of .position. and the CGRect. What do you think?
Topic: Programming Languages SubTopic: Swift Tags:
Dec ’23
Reply to Where do I place my code to instantiate my Project’s `struct` code within `SwiftUI`?
Thanks bunches, Claude31. Unfortunately it didn't work .. and I take full responsibility for that because I feel I did not fully explain all the details necessary to describe my goal .. I faithfully inserted all the code your doc stated should be placed within my viewDidLoad. It compiled okay.` My GameViewController consists of 2 vertical halves. The bottom shows several animated SKSpriteNodes that move. This bottom half is not the subject of my quest for help. It's the top half that contains my GameStaticObjects. As you can see in the above screen shot, this struct comprises 2 rows of static objects using HStack and Vstack. I discovered the latter that docs said would cause them to spread out edge-to-edge as the destination iPad rotated 90 degrees. In short, as the length of the string along which these HStack objects were strung, they would spread out and go edge-to-edge of the parent window frame. Before GameStaticObjects, these SKSpriteNodes were added in the addGamePieces function of my GameViewController via aSKScene.addChild(aSKSpriteNode). As already noted, however, the just talked about edge-to-edge rendition did not happen .. not to mention the fact there was a lot of hard coding required to set the position of each of these static objects. So, here I am .. I added all the code specified in your doc reference to my viewDidLoad function and nothing happened. I'm tempted to think that I need to add a small amount of code to the above addGamePieces function. I really apologize for being too wordy here .. but I don't know to do it differently so you are fully aware of where I am.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Dec ’23