2012-06-29 15 views
0

開關按鈕出現在我的所有其他圖層中,我在想是否有辦法只出現在某個圖層中。我實現了這個聲音,但它也在我的其他圖層中

.h文件中

UISwitch *muteSwitch; 

.m文件

 muteSwitch = [[ UISwitch alloc ] initWithFrame: CGRectMake(0, 290, 0, 0) ]; 
     muteSwitch.on = YES; 
    [muteSwitch addTarget:self action:@selector(soundOnOrOff:) forControlEvents:UIControlEventValueChanged]; 
    [[[CCDirector sharedDirector] openGLView] addSubview:muteSwitch]; 
    [muteSwitch release];    





    - (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]; 
} 

    } 

回答

1

,因爲你在GLView的頂部添加您的滑塊這是很正常的。所以即使你改變了場景,滑塊也會留在這裏。 如果你想刪除它,你只需要在改變你的場景時調用[muteSwitch removeFromSuperview]

我應該使用來自CCControlExtension的CCControlSwitch,因爲它是使用Cocos2D構建的,它可以像任何其他Cocos2D組件一樣工作。此外,您可以自定義它,只要你想。

相關問題