目标:我想呈现一个新场景:
[self.scene.view presentScene:level2 transition:reveal];
Run Code Online (Sandbox Code Playgroud)
并结束当前的背景音乐以启动新的背景音乐(2级的新背景音乐).
问题:在呈现新场景时,1.场景(level1)的背景音乐一直在播放,即使在离开迷你游戏时也不会停止,因为整个游戏由几个迷你游戏组成.
播放的音乐是SKAction:
@implementation WBMAnimalMiniGameLvL1
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size])
{
/* Setup your scene here */
self.temporaryScore = 0;
self.animalSKSprites = [[WBMAnimalsMiniGameModel alloc] init];
self.backgroundImage = [SKSpriteNode spriteNodeWithImageNamed:@"farmBackground1024x768.png"];
self.backgroundImage.position = CGPointMake(CGRectGetMidX(self.frame),
CGRectGetMidY(self.frame));
self.temporaryStartingPointIndex = -1;
[self addChild:self.backgroundImage];
self.playBackgroundSound = [SKAction playSoundFileNamed:@"farm.mp3" waitForCompletion:NO];
//SKAction *repeat = [SKAction repeatActionForever:playSound];
[self runAction:self.playBackgroundSound withKey:@"play"];
[self drawAllAnimalsOntoScreen];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
这是向下一级别的过渡发生的:
-(void)transitionToNextLevel
{
NSLog(@"transitionToNextLevel");
SKTransition *reveal = [SKTransition moveInWithDirection:SKTransitionDirectionDown duration:0.5];
//SKView *skView = (SKView *)self.view;
SKScene *level2 …Run Code Online (Sandbox Code Playgroud) 当我使用[self playSoundFileNamed]播放声音时,第一次播放声音会有一个小延迟,整个应用程序冻结大约半秒钟,但之后就没问题了.我怎么能摆脱这个?