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

     }
4

1 回答 1

1

这是很正常的,因为您将滑块添加到 GLView 的顶部。因此,即使您更改场景,滑块也会停留在此处。如果要删除它,只需[muteSwitch removeFromSuperview]在更改场景时调用 。

我应该使用 CCControlExtension 中的CCControlSwitch,因为它是使用 Cocos2D 构建的,并且可以与任何其他 Cocos2D 组件一样工作。此外,您可以根据需要自定义它。

于 2012-06-29T13:31:37.670 回答