我一直不知道如何摆脱暂停菜单上的滑块。我想知道是否有一段代码或任何想法,如果您单击恢复,您将终止控制音乐的滑块
./m 文件
-(void)PauseButtonTapped:(id)sender
{
if(_pauseScreenUp ==FALSE)
{
_pauseScreenUp=TRUE;
//if you have music uncomment the line bellow
//[[SimpleAudioEngine sharedEngine] pauseBackgroundMusic];
[[CCDirector sharedDirector] pause];
CGSize s = [[CCDirector sharedDirector] winSize];
pauseLayer = [CCColorLayer layerWithColor: ccc4(150, 150, 150, 125) width: s.width height: s.height];
pauseLayer.position = CGPointZero;
[self addChild: pauseLayer z:8];
_pauseScreen =[[CCSprite spriteWithFile:@"pause picture.png"] retain];
_pauseScreen.position= ccp(250,150);
[self addChild:_pauseScreen z:8];
CCMenuItem *ResumeMenuItem = [CCMenuItemImage
itemFromNormalImage:@"resume.png" selectedImage:@"resume.png"
target:self selector:@selector(ResumeButtonTapped:)];
ResumeMenuItem.position = ccp(250, 230);
CCMenuItem *QuitMenuItem = [CCMenuItemImage
itemFromNormalImage:@"quit.png" selectedImage:@"quit.png"
target:self selector:@selector(QuitButtonTapped:)];
QuitMenuItem.position = ccp(250, 50);
CCMenuItem *MainMenuItem = [CCMenuItemImage
itemFromNormalImage:@"mainmenubutton.png" selectedImage:@"mainmenubutton.png"
target:self selector:@selector(MainButtonTapped:)];
MainMenuItem.position = ccp(250, 145);
CCControlSlider *slider = [CCControlSlider sliderWithBackgroundFile:@"sound bar.png" progressFile:@"sound bar.png" thumbFile:@"sound icon.png"];
slider.minimumValue = 0.0f; // Sets the min value of range
slider.maximumValue = 1.0f; // Sets the max value of range
// When the value of the slider will change, the given selector will be call
[slider addTarget:self action:@selector(valueChanged:) forControlEvents:CCControlEventValueChanged];
[slider setPosition:ccp(240,68)];
[self addChild:slider z:8];
CCControlSlider *slider1 = [CCControlSlider sliderWithBackgroundFile:@"sound bar2.png" progressFile:@"sound bar2.png" thumbFile:@"devil2.png"];
slider1.minimumValue = 0.0f; // Sets the min value of range
slider1.maximumValue = 1.0f; // Sets the max value of range
// When the value of the slider will change, the given selector will be call
[slider1 addTarget:self action:@selector(valueChanged1:) forControlEvents:CCControlEventValueChanged];
[slider1 setPosition:ccp(240,8)];
[self addChild:slider1 z:10];
_pauseScreenMenu = [CCMenu menuWithItems:ResumeMenuItem,QuitMenuItem,MainMenuItem, nil];
_pauseScreenMenu.position = ccp(0,0);
[self addChild:_pauseScreenMenu z:10];
}
}
-(void)ResumeButtonTapped:(id)sender{
[self removeChild:_pauseScreen cleanup:YES];
[self removeChild:_pauseScreenMenu cleanup:YES];
[self removeChild:pauseLayer cleanup:YES];
[[CCDirector sharedDirector] resume];
_pauseScreenUp=FALSE;
}
-(void)QuitButtonTapped:(id)sender{
[self removeChild:_pauseScreen cleanup:YES];
[self removeChild:_pauseScreenMenu cleanup:YES];
[self removeChild:pauseLayer cleanup:YES];
[[CCDirector sharedDirector] resume];
_pauseScreenUp=FALSE;
[[UIApplication sharedApplication] performSelector:@selector(terminateWithSuccess)];
}
-(void)MainButtonTapped:(id)sender{
[self removeChild:_pauseScreen cleanup:YES];
[self removeChild:_pauseScreenMenu cleanup:YES];
[self removeChild:pauseLayer cleanup:YES];
[[CCDirector sharedDirector] resume];
_pauseScreenUp=FALSE;
[[CCDirector sharedDirector] replaceScene:[MainMenuScene scene]];
}
- (void)soundOnOrOff:(id)sender
{
if ([[SimpleAudioEngine sharedEngine] mute]) {
// This will unmute the sound
[[SimpleAudioEngine sharedEngine] setMute:0];
}
else {
//This will mute the sound
[[SimpleAudioEngine sharedEngine] setMute:1];
}
}
- (void)valueChanged:(CCControlSlider *)sender
{
// Change volume of your sounds
[[SimpleAudioEngine sharedEngine] setBackgroundMusicVolume:sender.value];
}
- (void)valueChanged1:(CCControlSlider *)sender
{
// Change volume of your sounds
[[SimpleAudioEngine sharedEngine] setEffectsVolume:sender.value];
[[SimpleAudioEngine sharedEngine] playEffect:@"boom.mp3"];
}
当我点击暂停菜单时,滑块出现,当我点击恢复时它不会消失:(。任何建议都会很好。我在想当你触摸恢复时可以消除或隐藏声音滑块的东西。