00:00
00:00
Newgrounds Background Image Theme

markololohands just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

OOP what goes on document class?

307 Views | 2 Replies
New Topic Respond to this Topic

OOP what goes on document class? 2013-08-03 18:11:15


When using OOP is there anything that just be tied to the Document Class? As I understand it, and please correct me if I am wrong as I am still trying to grasp OOP, whatever you place in the class that is tied to the document carries over throughout the entire game rather than just say everything that was on the first level.

Trying to figure out what should go in the document class (for example, character movement which remains the same throughout whole game) and what can be given its own class.

I know it may be vague as I am not giving details about the game and that's cuz I don't have any. I'm talking hypothetically if I were to make a game (and I plan too as I've been plugging away at programming for months) how do I know what needs there own class and what can go in the document class?

Thanks in advance guys. You are always so helpful :)

Response to OOP what goes on document class? 2013-08-03 18:34:06


Two ways I've seen it done: either your main menu (the one immediately after the preloader) or a "Game Engine" class will be your doc class. The first is easier, but gets kinda messy. The latter, you would only have references to the main game and any menus (you would add/removeChild the menus and game to display or remove them).

// Engine.as
private var game:Game;
private var mainMenu:MainMenu;

// blah blah
addChild(mainMenu = new MainMenu());
// play game
removeChild(mainMenu);
addChild(game = new Game());

// enterframe handler
// render handler

When you remove the main menu, you might want to include a "dispose" or "exit" method that gets rid of any stuff that won't be necessary for playing the game. Maybe remove all mouse listeners, stop any mcs, etc.

Following the one enterframe rule, it would go here. Then you would call game.update or menu.update or however you structure that.

Response to OOP what goes on document class? 2013-08-03 18:59:53


Thank you for your input MSGhero. You are always on here responding to my AS3 questions and I just want you to know that I greatly appreciate all the help you have given me :)