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]、シーンを変更するときに を呼び出すだけです。

Cocos2D でビルドされ、他の Cocos2D コンポーネントと同じように動作するため、CCControlExtension のCCControlSwitchを使用する必要があります。さらに、あなたが望むようにそれをカスタマイズすることができます。

于 2012-06-29T13:31:37.670 に答える