ios - How to add SKSpriteNode from nsarray at runtime without the frame rate going down -


What am I trying to do, before the gameplay begins, I'll need a level level, so I

I divided them into 4 arrays, each array corresponds to a square at the level, the level is divided into 4 squares.

So when the player moves forward in one part of the level, the scene adds all the sprites, it works almost perfectly, except that a slight drop in the frame rate sometimes happens when the scene array Adds sprites of

Is it possible to add sprites to runtime without affecting the frame rate?

Here's what I'm trying to do to explain some pseudo-codes.

SpriteClass.m

  _sprite = [[Sprite Alok] init]; _sprite.position = location; _sprite.anchorPoint = CG PointMake (.5, .5); _sprite.zPosition = 5; _sprite.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize: CGSizeMake (_sprite.size.width, _sprite.size.height / 4)]; _sprite.physicsBody.dynamic = NO; _sprite.physicsBody.restitution = 0.0; _sprite.physicsBody.categoryBitMask = PCFloor; _sprite.physicsBody.contactTestBitMask = PCPlayerCategory; _sprite.physicsBodyCollisionBitMask = PCPlayerCategory; _sprite.name = @ "Phantom"; if (_sprite.position.x> 4000) {[[Singleton Share] .spriteArray1 addObject: _sprite];} and if (_sprite.position.x> 4000 & amp; amp; ; _sprite.position.x & lt; 8000) {[[Singleton Share] .spriteArray2 addObject: _sprite];} And if (_sprite.position.x> 8000 & amp; amp; _sprite.position.x & lt; 12000) {[[Singleton shared] .spriteArray3 addObject: _sprite];} and if (_sprite.position.x> 12000) {[Singleton shared] .spriteArray4 addObject: _sprite];}  
< P> In myScene.m

Spnbox is a player, to know which player is in the section in which the player is connected.

  - (Id) InitWithSize: (CGSize) size {if (self = [super initWithSize: size]) {spawnNum = 1; [soulhana];} healthy return;} - (zero) spawn {switch (spannam) {for case 1: (int X = 0; xlt; [singleton is shared] .spriteArray1.count; ++ x) {[MyScene Adichil: [[Singleton is shared] .spriteArray1 addObject: _sprite]; ObjectAtIndex: x]]; } Spawnbox = secretemake (3500, 0, 32, _tileMap.mapSize.height * _tileMap.tileSize.height); ++ spawnNum; Switch (SpanName) {Case 2: for (int x = 0; x & lt; [singleton is shared] .spriteArray2.count; ++ x) {[MyScene Adbild: [[Singleton is shared]. SpriteArray2 addObject: _sprite]; ObjectAtIndex: x]]; } Spawnbox = secretemake (3500, 0, 32, _tileMap.mapSize.height * _tileMap.tileSize.height); ++ spawnNum; Switch (SpanName) {Case 3: for (int x = 0; x & lt; [singleton is shared] .spriteArray3.count; ++ x) {[MyScene Adichil: [[Singleton is shared]. SpriteArray3 addObject: _sprite]; ObjectAtIndex: x]]; } Spawnbox = secretemake (3500, 0, 32, _tileMap.mapSize.height * _tileMap.tileSize.height); ++ spawnNum; Switch (SpanName) {Case 4: for (int x = 0; x and lt; [singleton is shared] .spriteArray4.count; ++ x) {[MySassine Adshil: [[Singleton is shared]. SpriteArray4 addObject: _sprite]; ObjectAtIndex: x]]; } Spawnbox = secretemake (3500, 0, 32, _tileMap.mapSize.height * _tileMap.tileSize.height); ++ spawnNum; Default: Break; }}  

In addition, I am testing on iPhone 5C, 6, iPad Air, 1Gen iPad Mini.

Did you implement the removal sprites that are no longer visible? And you can easily try adding new sprites. I mean once not adding the whole section one time, but add some parts of your level while the levels rise.


Comments