I have a lot of characters in my game and because of that I have so many textures. When a texture atlas is loaded (containing about 5 different image textures) it increases the memory use and keeps it there at that amount. So the more textures just keeps driving that number up and up until sometimes the application crashes. I don't need all the characters at once, how can i maybe load some character textures when I need them and deallocate the others when i don't, but ill need to be able to bring it back.
相关问题
- What uses more memory in c++? An 2 ints or 2 funct
- “Zero out” sensitive String data in Swift
- SwiftUI: UIImage (QRCode) does not load after call
- Achieving the equivalent of a variable-length (loc
- Get the NSRange for the visible text after scroll
相关文章
- Using if let syntax in switch statement
- Enum with associated value conforming to CaseItera
- Swift - hide pickerView after value selected
- Is there a Github markdown language identifier for
- How can I vertically align my status bar item text
- Adding TapGestureRecognizer to UILabel in Swift
- Attempt to present UIAlertController on View Contr
- Swift - Snapshotting a view that has not been rend
Rule 1
First of all you don't need to manually load in memory your texture atlas. When you create a sprite with this code
SpriteKit looks for an image named
Dog
and if it cannot find it then it automatically looks for the image inside all your texture atlases.When the image is found inside a texture atlas the whole texture atlas is automatically loaded in memory.
Rule 2
Don't bother about removing the texture atlas from memory
When you stop using all the images inside a given texture atlas it is automatically removed from memory. This could not happen immediately if the system has "enough" memory but it will happen eventually.
What can you do?
You should group your textures into several texture atlases following the logic of your game.
If you have 30 textures and you know that only the 1...10 OR 11...20 OR 21...30 will be used at the same time then create 3 texture atlases like follow:
This will make the SpriteKit work more effective.