how to add a slider on cocos2d layer i.e directly on gamescene.m??
you cant add a UISlider directly as a cocos2d node to a layer/scene.
You have to add it as a subview to your cocos2d layer. here is an example:
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];
For the later version of cocos2d, don't need window in following statement. That support autorotation.
[[[CCDirector sharedDirector] openGLView] addSubview:sliderCtl];
精彩评论