We're working on a small game where we needed to put a UITableView to summarize the highest scores, but when it comes to load back a SKScene from the said UITableView the app suddenly stops (no crashes or errors in the console, it just stops and freezes), is there a way to bypass this? The high score section is loaded from the Home scene, the same Home scene I'm trying to reach from the high score tableView.
Can you provide code?
Make sure there is no breakpoint triggered that may stops your code while running.
And a recommendation From my experience - you should try to avoid combination between UIKit and SpriteKit, this will solve you allot of problems. There are many open source libraries (here is one) that helps build UI components out of SKNodes.
Related
I am pretty new at SceneKit and the first thing I noticed is the time it takes to load a DAE environment and characters. I've been looking for ways to show a loading screen while the environment is loading but none of them seem to work.
Whenever I push from menu screen to game screen, it would show around half of the menu screen and half of the game's screen with the UIKit components, and after about 3 seconds, then it shows the game screen without finishing the push animation transition. This is obviously not a good user experience so I would like to know how to add a loading screen until the environment shows up and preferably not freeze the UI because I want to find opponents in the backend as well as the user be able to cancel.
I currently have the entire views of game screen load in viewDidLoad. If you could provide an loading page example either a view or viewController that would be appreciated.
I created a custom UIKit progress bar to add some better affects and called a progressUpdate to move the bar. A gameNodes (sharedInstance) class where I cache and share node information with other classes. gameNodes->loadModels() does a call back every N/Total to update the bar. In gameViewController->viewDidLoad, I loaded the models after I created UIKit components and aligned them. I tried a splash screen to help, but I must have done it wrong because it never really worked. There is some wait time because scenekit had to load (in my case), so it wasn't perfect on all devices. However, it did produce what I felt like was reasonable feedback as the models were loading.
I've seen this concept mentioned around the internet but can't find any specifics on how to do it.
I want to lay out my entire level in an .sks file but load only whats in the view of the player/frame at any given moment. In my game I have platforms that go up and down forever, simple roving enemies, and collectable coins that float in the air while bobbing up and down. Since these actions are using
SKAction.repeatForever
They are continuously going even when not in view of player. The only other option I see is giving every action a "key" and then placing invisible sprites through out the level that when contacted start and stop certain actions. While doable it seems it could get very convoluted very fast.
Is there a more straightforward way to lay out my entire scene, but only load what's currently in view? I'm not sure what to call this concept which is probably the reason I can't find much on it.
Any insight is appreciated!
There is no easy way to do it. My personal method is to load your SKS into an SKScene that is not attached to the root node at all (the SKView) and use SKCameraNode's containedNodeSet to move all nodes from the loaded scene over to the scene that is viewable to the user. You would then need to implement methods to continuously swap between the two scenes.
If your concern is only actions, then you can avoid the swapping and just pause all nodes not in the containedNodeSet and unease the ones that are inside of it.
I am an experience programmer, but a newbie to IOS trying to finish off a game and am having trouble with memory running away.
The problem I am seeing can be reproduced simply with al,most no custom code: To simplify, I started with the out-of-the box apple sample project: openGlGame, which produces a single view of spinning cubes. I then added a startup view/controller in front of the spinning cube view/controller. I then added a button on each screen with a segue and an unwind, respectively, so I could go back and forth between a blank startup view, and the spinning cubes.
When profiling this project (using "Allocations"), every time I go back and forth between the views, the memory allocated for the coreAnimation object increases by over 10MB !!
This is roughly the same thing that is happening in my game.
Why is this memory running away? Is there something overlooked in the sample project? Is there something I am overlooking?
Thanks in advance.
I am attempting to determine the best way and most efficient way to handle the following tasks in a game written with the Corona SDK. It seems like there are so many ways to do things that it becomes quite confusing, so I am hoping someone here can help!
I am creating an adventure type game that will have an inventory system/puzzles etc. The thought process I've developed so far involves using separate "classes" to handle each specific aspect of the game. Such as InventoryManagement.lua, ObjectManagement.lua, PuzzleManagement.lua etc.
Just a side note - this game really doesn't involve Physics, but I would like to have static images with animations that occurs (Think opening a door or picking up an object):
Here is an example of what I am trying to accomplish:
Say you start a new game and it loads the first scene. I need to setup the player's inventory, the objects in the room, their state, images for these things etc. which I assume could be defaulted on first game load, and loaded subsequently ...
Then the player clicks on a key to pick it up - at this point the key needs to appear in their inventory so now it will be removed from the scene, added to their inventory (Via InventoryManagement?), and the scene will be updated (Via SceneManagement?)...
From now on the key should no longer show in the scene.
Now say they click the key and use it on a door, the door should animate open and remain open from now on.
If the player leaves the room and comes back, the key should not appear.
Now to me it makes sense to load/unload the scene every time you enter/leave the scene, but ... won't this become memory intensive etc. if you do it this way? ... Is there a better way to handle a scene if it has say, 30 objects on screen?
Hopefully that is clear - It is hard to find specific information related to each one of these elements. Everything seems to be related to physics games and I can't seem to find something on how to "Add a key to the scene if, but not if, and if it's been used then animate that door" :(
Thanks!
Had the same problem with unexpected results when jumping between storyboards. One thing I found out was
Always make sure to Runtime:remove and stop the timers you use. One alternative when you want to reset everything is to make a reset.lua file and on enterScene you use storyboard.removeScene or storyboard.purgeScene (If you just want to get rid of all display objects you have rigged up in memory in scene:createScene).
Also check out storyboard.RemoveAll() or purgeAll()
You need to make some stuff in Global space (using _G) to use them between scenes.
To change between scenes, "Storyboard" is very nice.
But mind you, you will need to use some manual memory hacking if you make things too much memory intensive, mainly, you might need to before loading a scene, do several calls of "collectgarbage" after cleaning the last scene, otherwise you will hit a curious problem:
You loaded scene "A".
You switch to scene "B".
The game 'unloads' "A", but the garbage collector don't, then loads "B", the end result is memory use of "A" + "B".
On this adventure game I was making in Corona, it resulted in several crazy crashed until I figured the "collectgarbage" trick.
I have this problem with performance of my iPad app..
For developing, I use MonoDevelop, which takes care of Garbage collecting. Still my questions are rather generic, I'd say.
OK, I use TabBarController with 5 NavigationControllers. Inside nav controllers there are some controllers, whose views are TableViews or ScrollViews. Next child is always just regular view.
I have a few questions:
1) TableViews never scroll smoothly. I have some alpha transparency, but since I did my graphics in Photoshop and not programmatically, this transparency should not cause much problems. It doesn't matter whether I have few or many results in table.
On the other hand, I have ScrollView which serves same purpose, i.e. to be a table with different layout and buttons have Photoshop generated transparency as well. It works perfectly.
For tables I applied DequeueReusableCell() which works fine (I see that memory usage is not increasing after scrolling). So why would tables scroll so jerky?
2) My app supports rotation. When I scroll table or scrollView and simultaneously tilt the device a bit, I get maybe 1 or 2 FPS. What is the best way to implement rotation? As I understand, ShouldAutorotateToInterfaceOrientation has to be overridden in all controllers in NavigationController chain. Also, I need to add observer in View I want some changes to happen. Do I have to use BeginGeneratingDeviceOrientationNotifications() in all views or is it enough to do it in Main.cs? Maybe this slows it down?
3) After some time app starts getting memory warnings and then crashes eventually. I tried to read logs and run app with Instruments, but can't find the cause of crash.
4) What exactly happens to a View popped from NavigationController stack? I can't reuse it. But could it be that Monotouch (or me) doesn't dispose it correctly?
I have almost same app for iPhone without support for rotation which never crashes. I think I'm doing something wrong with this rotation, but I'm not sure what.
Any help will be appreciated the most. So, thank you in advance.
Regards
1 - transparencies are always a problem. Even if you're not rendering the images in code, the phone still needs to do the compositing of the image, and that may take a lot of time. UITableViews have to calculate the final composite image every time a new cell is displayed, or the table is scrolled, while UIScrollViews can calculate only once, since the image won't change. So be very careful about it, turn the transparency off, and check if performance improves.
2 - You shouldn't need to notify every uiview in your application. Receive the notification in the controllers that you want to update only, like for example if you want to rearrange items in the UIViewControllers view.
3 - you have one (or many) memory leaks. My guess is that MonoTouch probably can't garbage collect UIViews or UIViewControllers, because they're still being linked from somewhere in UIKit, like a UINavigationController
4 - UIViews are not disposed by UIKit until the app gets a memory warning notification.
Like Eduardo said, alpha transparency in Views comes at a price. There are some tools that you can use to identify the bottlenecks discussed in these WWDC 2011 talks from:
https://developer.apple.com/videos/wwdc/2011/
iOS Performance and Power Optimization with Instruments
Understanding UIKit Rendering
In the "Debug" menu of the iOS simulator you can find various debugging tools that will color different regions of the screen indicating where some problematic rendering is taking place. The WWDC 2011 talks show what you can do to fix those problems.
For your memory problems, it is very likely that you have something pointing out to your objects around, so you need to make sure those objects are gone. While we currently are not shipping our new profiler for MonoTouch that can show the source of the problem, I wrote a "poor man's" debug utility that will help you narrow down which objects are alive. It is available here:
http://tirania.org/tmp/HttpDebug.cs
Call HttpDebug.Start () from your application and as you run, connect with a web browser to http://localhost:5000 to get a list of live Objective-C objects surfaced to C#. The tool is not perfect and shows a lot of irrelevant data, but it would at least give you an idea of what is going on.