1

I'm building an app using Spritekit, I use UISwipeGestureRecognizer to swipe between scenes.

Now, my app is going to have a lot of scenes based on the same code, and the swipe gesture works well, except once I add a third or fourth scene I get a lot of swipe lag.

I'm not sure if it's because I'm using too many scenes or if it's because each scene uses a background image.

The swipe works but it suffers from a significant lag.

Am I the only one getting this issue? Has anyone found a work around for this kind of lag?

Any help would be appreciated.

Here's an example of the code used for 1 scene.

Thank you

#import "Ep1Slide1.h"
#import "Ep1Slide2.h"

-(id)initWithSize:(CGSize)size {
  if (self = [super initWithSize:size]) {

       self.backgroundColor = [SKColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0];
       CGImageRef backgroundCGImage = [UIImage imageNamed:@"backgroundImage1"].CGImage;
       SKTexture *backgroundTexture = [SKTexture textureWithCGImage:backgroundCGImage];
       SKSpriteNode *someNode = [SKSpriteNode spriteNodeWithTexture:backgroundTexture];
       someNode.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
       [someNode setScale:0.5f];
       [self addChild:someNode];
       }
     return self;
   }

- (void)didMoveToView:(SKView *)view{

       UISwipeGestureRecognizer *leftSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action: @selector(leftFlip:)];
       [leftSwipe setDirection:UISwipeGestureRecognizerDirectionLeft];
       [self.view addGestureRecognizer:leftSwipe];
   }


- (void)leftFlip:(id)sender{
       SKView * skView = (SKView *)self.view;
       SKScene * scene = [Ep1Slide2 sceneWithSize:skView.bounds.size];
       scene.scaleMode = SKSceneScaleModeAspectFill;
       [skView presentScene:scene transition:[SKTransition pushWithDirection:SKTransitionDirectionLeft duration:1.2]];
   }
PhilBlais
  • 1,076
  • 4
  • 13
  • 36
  • 1
    uhm any reason why you don't create the sprite from image directly? The uiimage->cgimage->texture path adds a lot of unnecessary overhead, and it means you aren't using a texture atlas that you could preload to avoid the image loading overhead on each scene change. – CodeSmile Jun 04 '14 at 07:15
  • 1
    I would consider preloading the textures you use in the new scene. Loading the textures *will* delay the presentation of new scene, so best do that before you present the new scene! I would suggest you take a look at my answer to [this question](http://stackoverflow.com/questions/22130857/not-working-transitions-in-spritekit/24016057#24016057) (which I believe to be related if not the same problem). – CloakedEddy Jun 05 '14 at 11:39
  • 1
    I've tried loading an image directly, but this way I end up with better memory management. But regardless, the lag/slowdown happens as well. I will try preloading, sounds like a very good idea. texture atlas is limited to 2048 x 2048, which doesn't help much in my case. – PhilBlais Jun 05 '14 at 16:39

0 Answers0