Original Post
Hey
In my class i have a private function which has this:
[source lang="cpp"] void Application::init(){
CreateSprite Background(theme["Background"]);
CreateSprite Logo(theme["Logo"]);
CreateSprite Button(theme["Button"]);
CreateSprite ButtonOn(theme["ButtonOn"]);
run(1);
}
void Application::run(int gameBool){
while(gameBool){
//game loop
}[/source]
The problem is - i cannot access my sprites (due to scopes).
So how do game makers do this ?
The way i thought was something like using a setting like so:
[source]std::string Setting = "MainMenu";[/source]
Then in run i would have:
[source lang="cpp"] void Application::run(int gameBool,std::string &Setting){
while(gameBool){
switch(Setting){
case "MainMenu": loadMainMenu result(); //this would be a class that sets sprites instead of doing so in "init()"
}
window.clear();
result.updateTo(window); //this will have window.draw() for all the sprites in the class
window.display();
}
[/source]
Am i on the right lines to how games are best programmed? Or is there some neat trick I'm missing.
In my class i have a private function which has this:
[source lang="cpp"] void Application::init(){
CreateSprite Background(theme["Background"]);
CreateSprite Logo(theme["Logo"]);
CreateSprite Button(theme["Button"]);
CreateSprite ButtonOn(theme["ButtonOn"]);
run(1);
}
void Application::run(int gameBool){
while(gameBool){
//game loop
}[/source]
The problem is - i cannot access my sprites (due to scopes).
So how do game makers do this ?
The way i thought was something like using a setting like so:
[source]std::string Setting = "MainMenu";[/source]
Then in run i would have:
[source lang="cpp"] void Application::run(int gameBool,std::string &Setting){
while(gameBool){
switch(Setting){
case "MainMenu": loadMainMenu result(); //this would be a class that sets sprites instead of doing so in "init()"
}
window.clear();
result.updateTo(window); //this will have window.draw() for all the sprites in the class
window.display();
}
[/source]
Am i on the right lines to how games are best programmed? Or is there some neat trick I'm missing.