Post

Replies

Boosts

Views

Activity

Reply to How do I stop a node as it is moving around a UIBezierPath and then restart the moving from where it stopped?
===== SOLVED SOLVED ===== I placed print("pause index =", savedTrainIndex)after pausing the game and got 160, e.g. I also placed print("resume index =", savedTrainIndex) before resuming and got 160 as it should be as the node was moving along the top half of the oval. Then, as the node was moving along the bottom half of the oval, I got 90. Here is the response I received from Apple Deve;loper Tech Support - which worked flawlessly: When you run the follow action on a node, SpriteKit will set the position of the node to the starting position of the provided path. The issue you are observing (when the train makes large jumps in position) is caused because of large differences in the node’s current position compared to the follow path’s starting position. This large difference is due to a bug in your code, specifically in the closestPointInPath function, which appears to be an algorithm that tries to determine the point on the path that is closest to the current position of the node, which you then use to calculate the starting point for the new follow path. If you replace that function with this one (which contains a naive implementation to find the closest point to the target point), you will see that the large position jumps no longer occur: public func closestPointInPath(_ path:UIBezierPath, toPoint:CGPoint) -> CGPoint? { let targetPoint = toPoint let thePoints = getPointsForPath(path) var closestPoint = CGPoint.zero var minDistance = CGFloat.infinity for point in thePoints { let distance = distanceBetween(point, targetPoint) if distance < minDistance { minDistance = distance closestPoint = point } } return closestPoint } Mr. Chistie from Apple DTS is out-of-sight awesome. Once again, I labor for 3 weeks and DTS solves the problem in 3 days.
Nov ’24
Reply to How do I stop a node as it is moving around a UIBezierPath and then restart the moving from where it stopped?
===== new discovery ===== I placed print("pause index =", savedTrainIndex)after pausing the game and got 160, e.g. I also placed print("resume index =", savedTrainIndex) before resuming and got 160 as it should be as the node was moving along the top half of the oval. Then, as the node was moving along the bottom half of the oval, I got 90. I think this is the key to my challenge because I believe after stopping and then restarting along the bottom half of the oval, the stop/restart index should be a number > 160, not 90. In short, shouldn't the index monotonically increase as it is traveling along the whole oval? Anyway, I am currently investigating this discrepancy. Don't know if it will lead to a solution or not at this time.
Nov ’24
Reply to How do I correctly show a PDF document?
I'm getting there ... Again, I call addPDFView() + displayPDF("ABOUT_OLD_WEST_LOCOMOTIVE.pdf" within my specific SKScene's sceneDidLoad() because I have multiple SKScenes. and an empty PDFView shows ... which tells me my Project is not seeing my .pdf file. I do not understand this because when I select my Target's Build Phases and expand Copy Bundle Resources, the above .pdf file is listed. ???
Jul ’24
Reply to How do I correctly show a PDF document?
Please note that the only reason I do not place all the PDFView code in my GameViewController is because I have 3 SKScenes, only one of which uses a PDFDocument. As a result, I add the PDFView to all SKScenes within my GameViewController and then fill it in the one SKScene that will show the PDFDocument. As long as I am asking for help, how do I successfully place my pdfView on top Being a UIView, it has no .zPosition?
Jul ’24
Reply to How do I correctly show a PDF document?
Starting over with the suggestions offered so far, I have this in AppDelegate: var pdfView: PDFView! In my GameViewController’s viewDidLoad(), I call: `addPDFView()’ which looks like this: func addPDFView() { pdfView = PDFView(frame: self.view.frame) pdfView.displayMode = .singlePageContinuous pdfView.autoScales = true pdfView.displayDirection = .vertical view.addSubview(pdfView) } // addPDFView Then, in my SKScene’s sceneDidLoad(), I call: displayPDF("ABOUT_OLD_WEST_LOCOMOTIVE") which looks like this: func displayPDF(_ itsName:String) { guard (thisSceneName == "AboutIOSScene") else { return } let pdfView = PDFView() // see GameViewController's addPDFView() guard let path = Bundle.main.path(forResource: itsName, ofType: "pdf") else { return } print("path =", path) guard let pdfDocument = PDFDocument(url: URL(fileURLWithPath: path)) else { return } print("pdfDocument =", pdfDocument) pdfView.document = pdfDocument } // displayPDF Once again, the 2 print statements are shown .. but no pdfView.document John
Jul ’24