在级别选择屏幕中有菜单项并且根据所选的项目级别启动...这里是code..where selectedLevel是menuItem的索引。
if(selectedLevel==0)
{
activeScene = [level2_1Scene node];
[[CCDirector sharedDirector] pushScene:activeScene];
}
else if(selectedLevel==1)
{
activeScene = [level2_2Scene node];
[[CCDirector sharedDirector] pushScene:activeScene];
}
else if(selectedLevel==2)
{
activeScene = [level2_3Scene node];
[[CCDirector sharedDirector] pushScene:activeScene];
......等等所有级别
我怎么能用简单的级别场景名称格式做这样的事情呢?
activeScene = [[NSString stringWithFormat:@"level2_%d",selectedLevel+1] node];
[[CCDirector sharedDirector] pushScene:activeScene];
答案 0 :(得分:2)
我的一个工厂的这个片段可能会在改编后做你的伎俩:
Skill *skkk = (Skill *) NSClassFromString(className);
if (skkk) {
return (Skill *) [[skkk class] skillWithSpec:ss];
} else {
MPLOGERROR(@"*****************************************************************");
MPLOGERROR(@" no class with name %@", className);
MPLOGERROR(@"*****************************************************************");
return nil;
}
答案 1 :(得分:0)
这对我有用,,,
NSString *level=[NSString stringWithFormat:@"level2_%dScene",selectedLevel+1];
Class sceneClass = NSClassFromString(level);
activeScene = (bunnyScene*)[sceneClass node] ;
[[CCDirector sharedDirector] replaceScene:activeScene];
答案 2 :(得分:0)
我想这可能就是你要找的东西:
switch(selectedLevel)
{
case 0:
activeScene = [level2_1Scene node];
break;
case 1:
activeScene = [level2_2Scene node];
break;
// Etc....
}
if(activeScene) {
[[CCDirector sharedDirector] replaceScene:activeScene];
}