-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot intercept callbacks during loading map.. #3
Comments
I've implemented a delegate in the next release to handle completions, I'll try and get the delegate working and pushed this weekend. |
Thank you sir, very appreciated.. |
I was thinking to something about (just if this can help..):
and below:
So, in my project I can intercept this callback:
|
That's pretty cool! I just pushed up a revision with a similar setup: public protocol SKTilemapDelegate: class {
func didRenderMap(_ tilemap: SKTilemap, completion: (() -> ())? )
} The new callback is called after parsing is complete and all of the layers have finished rendering asynchronously. If you're using the included You can use it like this (here the scene is the delegate): if let tilemap = SKTilemap.load(fromFile: filename, delegate: self, completion: nil) {
// do stuff with the tilemap here
} Let me know if this works for you, or if you have any other requests. |
Hello sir, I'm here. First of all I like your way to write code, you think very well in Swift 3. As you see my protocol contain I think there is a problem with completion , the callback is fired so the delegate work, the tilemap var is full but the completion is equal to nil I've investigate to your sources and completion result nil always inside source. Why? Seems the problem start when you allow the user to do:
Pay attention, in my honest opinion that's great! but in your sources you say that if user don't explicit
I've think about this solution below where, if user put a completion I use it, but if the user don't care about completion I create it to use and propagate it to the rest of the code so callbacks have completion not equal to nil since the first launch, and not less important, without touching the other code...:
That code to better understand what happened but I think you could correct it in a short form as:
BUT there is another problem if an user decide to use completion since the first load as:
because even after my correction this completion is fired before the async queue Maybe you have a better idea or we can use this one. You choose. Ah, great project, again congratulations. I use it for my new game. |
Hi Alessandro, Thanks for the sample code. It's kind of a busy week here in the US, but I am taking a look at this.
The When I put in a simple test closure, it gets called at the end of the Here's a modified & simplified version of the override open func didMove(to view: SKView) {
let myClosure = {
if let tilemap = self.tilemap {
print("-> tile map loaded with \(tilemap.layerCount) layers")
}
}
if let tilemap = loadTilemap(fromFile: self.tmxFilename, completion: myClosure ) {
// do stuff here
}
} When I run this, the last thing displayed in the console is:
As I said, I'm happy to take it out or change it to something that works. |
I don't use |
Ah yes, you are absolutely correct. Thanks for bringing this to my attention. The problem is that in the current code the completion is unwrapped and executed in the in my sample scene, but that won't happen if you are building your own SKScene. It should really be executed in the parser when the dispatch queue is completed. Do you even foresee a need to have a completion closure in the callback? I've been using it primarily for debugging purposes, but the delegate would be cleaner if I simply removed the completion and let users do all of the post-processing in their delegate. |
I agree with you. You could remove the completion of the load function and use only the delegate to close every reasonable doubt. I do not know but I think that to be able to leave this completion you should rebuild the loading flow for using to a raw SKScene: it might not be worth it. I'd say something more useful to your project might be instead to include a Swift sprite activity indicator kit that says "Loading .." simple and a little customizable, because in a game that loads the map layers, controls (joystick, buttons ...) go off until the map is not fully charged then it could be just a value added to your project. But this is only my personal opinion, you may look to a large scale. |
Oh I forgot, for me this issue is closed because you've solved adding delegate for callbacks so for me that's enough, thank you. |
How can I intercept the end of the map loading without completions or delegate if my code follow your home instructions? How can I use callbacks?
after this line if I try to get a SKLayer, is always nil (I suppose because the map don't finish to load all components..) ..
Thank you in advance.
The text was updated successfully, but these errors were encountered: