-1
如何在cocos2d层上添加滑块,即直接在gamescene.m上添加滑块?滑块在cocos2d
如何在cocos2d层上添加滑块,即直接在gamescene.m上添加滑块?滑块在cocos2d
你不能直接添加一个UISlider作为一个图层/场景的cocos2d节点。
您必须将它作为子视图添加到您的cocos2d图层。这里是一个例子:
UISlider *sliderCtl = [[UISlider alloc]
initWithFrame:CGRectMake(170, 0, 125, 50)];
[sliderCtl addTarget:self action:@selector(sliderAction:)
forControlEvents:UIControlEventValueChanged];
sliderCtl.backgroundColor = [UIColor clearColor];
sliderCtl.value = 0;
[[[[CCDirector sharedDirector] openGLView] window]
addSubview:sliderCtl];
对于更高版本的cocos2d,在下面的语句中不需要窗口。这支持自动转换。
[[[CCDirector sharedDirector] openGLView] addSubview:sliderCtl];