I have a routine which adds a few hundred (mainly TGLextrusionsolid) objects into the scene.
The routine loads all the objects into GLscene with no problems in a few milliseconds but after exiting the loading code and allowing entry back into the main processing loop the program hangs for several seconds.
I presume this is caused by GLscene building the scene in its internal routines.
Once the scene appears on the screen after a few seconds, everything is fine, it can be rotated and zoomed at full speed.
Is this long delay between loading the objects and the scene apearing on screen normal?
Is there any way to stop it hanging the main thread whilst its doing its stuff?
Related
I have a UIView that sets a timer and each firing it generates a UIImage on a background queue (priority .userInitiated), and when finished (measured to take between 1-2 milliseconds, it pushes to the main queue and updates a UIImageView's image.
This creates a smooth animation effect (e.g. if the Timer is configured to fire 30 times per second). Touching the screen however either slows down or completely shuts down the updating. I removed my overrides of touchesBegan,Moved,Ended and any GestureRecognizers to ensure that I wasn't doing anything expensive. Simply touching the screen (especially dragging quickly) prevents the UI updating.
I watched this and googled as many SO posts as I can but I'm completely stuck on this.
Here is a reproduction of the problem. Run the app and it will display a stripped down rendering of a basic project. From there, you can drag/touch the screen and notice the frames will either slow down to a crawl or completely stop.
Github Repro
I am building a new game in SpriteKit and each time I want to restart the game I switch scenes, therefore each time I press "play again" my GameScene is loaded from the beginning and this causes my FPS to continuously drop.
So this is causing my FPS to drop overtime since each time I press play I have to basically load the whole new GameScene and the game on it (which is mostly spawning nodes). I believe that if there is no way in capping the FPS at a certain rate, then I should not use transitioning between 2 scenes.
However, I tried the method where I keep everything in 1 scene but unfortunately it did not work out since each time I pressed restart, the amounts of SKSpriteNodes that were spawning doubled. So the spawning of nodes and my timer speeds up by 2 times each time I play again. I don't know how to figure this issue out.
Everytime you change the scene , it should be removed from memory with its children.
You can add this method at the end of your scene:
deinit {
print("\n THE SCENE \(type(of: self))) WAS REMOVED FROM MEMORY (DEINIT) \n")
}
If you don't see in you debug console this print maybe you have a strong reference to self somewhere in your code.
You can follow the official guide to "Resolving Strong Reference Cycles for Closures"
I have a scene in my game view controller but i want to kill it when the player dies. This is because when the player restarts the game the fps decreases as the previous scenes are still running. My game runs on being repetitive and so there are multiple places where functions are called every point second. This is why the fps keeps decreasing. How can i input a method to kill the scene.
I previously used the code removeAllChildren() but that didn't cover it and the reason why was i needed the code removeAllActions() as well
I want to load Collada files dynamically in SceneKit at runtime. I have used copySceneKitAssetst to generate the .DAE file and put it my server. The app can download it from the server and use this file to init a SCNScene (refer to http://www.the-nerd.be/2014/11/07/dynamically-load-collada-files-in-scenekit-at-runtime/).
There is no error when executing "./copySceneKitAssets" and the models can be rendered properly. I have called [scnView prepareObject:gameScene shouldAbortBlock:NULL] before setting gameScene to the scnView.scene.
The problem is that the first time scnView renders the gameScene, its very slow (a few seconds). Even the main thread is blocked during this period which means UIs cannot refresh,h and sometimes the app is killed by iOS.From the second time it renders the scene,it's very fast and main thread works well.But if we delete the App and reinstall it,the problem comes again.
Any help is appreciated.
I think prepareObjects(_:withCompletionHandler) (defined on SCNSceneRenderer) is worth a look. It loads resources on a background thread.
I have this iPhone app created in Cocos2d 2.1.
WHen the app first starts it presents a full screen background and a UIACtionSheet where the user has to choose one option to start the application. That's it. This actionsheet is presented by the first scene to run by the delegate (HelloWorldLayer scene).
Nothing else is loaded. Nothing is running on any thread that I am responsible for that. Even so, the CPU usage is about 20%. I have profiled that on instruments and this is what I have:
I see this [CCGLView swapBuffers] that is inside something that calls attention, ths CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION (CoreFoundation).
If I choose "show obj-c only" I see this:
Apparently the guilty is this drawScene but how can a scene with a background image and a UIActionsheet use that much CPU?
How do I trace the source of this problem?
NOTE. This is being tested on the device. On simulator CPU usage is 77%!!!!!
Cocos2d, like any OpenGL application, redraws the contents of the screen every frame. Typically that means 60 frames per second. Swapping the frame buffers and all the other overhead associated takes some CPU time.
So what you're observing is normal behavior, there's nothing that can be done about it. There is no concept of "idle" in a rendering engine, it draws the contents of the screen even if they didn't change (or the screen is empty) on the assumption that screen contents usually do change.
You can however pause the CCDirector to reduce framerate, conserving CPU cycles and battery. Or call stopAnimation to completely stop all updates, including scheduled selectors. However what happens to the framebuffer is undefined, usually it sticks around (ie the last rendered frame "freezes") but this may not be true for all situations and devices.
As far as Simulator is concerned: ignore it. Its performance characteristics are not the least bit comparable nor instructive.