Ok, i've been trying to figure this out and searching the web and the forum but I haven't had any luck yet.
What I want to do is the following. I have a MainMenuScene which is a SKScene. Since I have added a number of SKActions and other things in that scene I wanted to be able to break it up into different files. So, for example, when the player presses the "Settings" button I would use a different file to write what would happen instead of using the MainMenuScene and make it even larger.
So my question is this: I want to be able to reference the SKScene in MainMenuScene.m from my SettingsSubScene.m file. The SettingsSubScene.m is the following:
#import "SettingsSubScene.h"
@implementation SettingsSubScene
{
SKScene *_mainMenuScene;
}
-(id)initWithScene:(SKScene *)mainMenuScene {
_mainMenuScene = mainMenuScene;
return self;
}
-(void)displaySettings {
SKSpriteNode *settingsGearLarge = (SKSpriteNode *)[_mainMenuScene childNodeWithName:@"settingsGearLarge"];
SKSpriteNode *background = [SKSpriteNode spriteNodeWithImageNamed:@"settings"];
background.anchorPoint = CGPointMake(0, 1);
background.position = settingsGearLarge.position;
background.zPosition = 0;
background.xScale = 0;
background.yScale = 0;
[_mainMenuScene addChild:background];
SKAction *appear = [SKAction scaleTo:1.0 duration:0.5];
appear.timingMode = SKActionTimingEaseInEaseOut;
[background runAction:appear completion:^{
[SKActionEffects fullScale:background amount:0.05 forever:YES];
[SKActionEffects fullWiggle:background amount:1 forever:YES];
}];
}
-(void)hideSettings {
}
@end
And I call it from MainMenuScene.m using the following code:
SettingsSubScene *settingsSubScene = [[SettingsSubScene alloc] initWithScene:self];
[settingsSubScene displaySettings];
And I get an exc_bad_access error. Of course i'm doing something wrong and I bet there is a way to do this instead of creating a large MainMenuScene file but I haven't found it yet. Can anyone help please?
Thanks