My question is, which one is better to use? How to properly use a switch statement. Should I use variables or not etc. I thank you in advance for your reply. "random text because I need a lot of explanation or else it won't let me post."
switch(level_id)
{
case 1:
stage.addChild(new lvl(50, 200, 100, level_id));
break;
case 2:
stage.addChild(new lvl(50, 200, 100, level_id));
break;
case 3:
stage.addChild(new lvl(50, 200, 100, level_id));
break;
case 4:
stage.addChild(new lvl(50, 200, 100, level_id));
break;
case 5:
stage.addChild(new lvl(50, 200, 100, level_id));
break;
case 6:
stage.addChild(new lvl(50, 200, 100, level_id));
break;
case 7:
stage.addChild(new lvl(50, 200, 100, level_id));
break;
default:
break;
}
or
switch(level_id)
{
case 1:
x = 50; y = 200; x = 100;
break;
case 2:
x = 50; y = 200; x = 100;
break;
case 3:
x = 50; y = 200; x = 100;
break;
case 4:
x = 50; y = 200; x = 100;
break;
case 5:
x = 50; y = 200; x = 100;
break;
case 6:
x = 50; y = 200; x = 100;
break;
case 7:
x = 50; y = 200; x = 100;
break;
default:
break;
}
stage.addChild(new lvl(x, y, z, level_id));
What I finally did (edit)
Final result, thanks all
var config:Object = {
"1":{ "paddWidth":50, "blockWidth":200, "blockHeight":100 },
"2":{ "paddWidth":50, "blockWidth":200, "blockHeight":100 },
"3":{ "paddWidth":50, "blockWidth":200, "blockHeight":100 },
"4":{ "paddWidth":50, "blockWidth":200, "blockHeight":100 },
"5":{ "paddWidth":50, "blockWidth":200, "blockHeight":100 },
"6":{ "paddWidth":50, "blockWidth":200, "blockHeight":100 },
"7":{ "paddWidth":50, "blockWidth":200, "blockHeight":100 },
"8":{ "paddWidth":50, "blockWidth":200, "blockHeight":100 }
};
stage.addChild(new lvl(
config[level_id].paddWidth,
config[level_id].blockWidth,
config[level_id].blockHeight,
level_id
));