Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualthefollower

Posted 12 November 2012 - 07:12 PM

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:

std::string Setting = "MainMenu";


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.

#3thefollower

Posted 12 November 2012 - 07:11 PM

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:

std::string Setting = "MainMenu";


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 draws everything it would also create the sprites instead of doing so in "init()" } window.clear(); result.updateTo(window); //this will have window.draw() for all the sprites window.display(); }[/source]

Am i on the right lines to how games are best programmed? Or is there some neat trick I'm missing.

#2thefollower

Posted 12 November 2012 - 07:11 PM

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:

std::string Setting = "MainMenu";


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 draws everything it would also create the sprites instead of doing so in "init()" } window.clear(); result.updateTo(window); //this will have window.draw() for all the sprites window.display(); }[/source]

Am i on the right lines to how games are best programmed? Or is there some neat trick I'm missing.

#1thefollower

Posted 12 November 2012 - 07:10 PM

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:

std::string Setting = "MainMenu";


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 draws everything//it would also create thesprites instead of "init()" } window.clear(); result.updateTo(window); //this will have window.draw() for all the sprites window.display(); }[/source]

Am i on the rights lines to how games are best structured?

PARTNERS