views:

213

answers:

3

Hi all, Doing a bit of research on dependency injection frameworks for AS3 to retain loose-coupling of classes and boost our re-usability of code. I've been looking heavily at RobotLegs. There's a whole lot I still don't understand about the framework but it seems ideal for our regular Rich Media apps but has anyone used this framework for AS3 games? if so is it a good framework for games or should I be looking for another framework? I've heard that the MVC pattern isn't ideal for game design but would love to be set straight on this :)

I'd love to hear from anyone who's used a dependency injection framework for games, how it faired for them!

Cheers, Anton

A: 

AS3 is not my business at the moment, but game-frameworks are ;) So, yes and no, MVC pattern are not your first choice, because you do not create that much views, controllers and models.

You have something more like an interface, some generic "engine" processing the game mechanic, and some database tables.

I currently use some aspects of MVC but not the complete pattern - "just the benefits".

EDIT: You "can not say that:" MVC is not designed to be used inside a game (engine), because the MVC pattern only describes a logic, and not something pre-defined, like "the code always has to contain $x and must begin with include($y)". It is just a design pattern, which does not directly affect the quality of the code, rather the progress and how you go on with your game design.

daemonfire300
+1  A: 

RobotLegs is brand-new, so you'll struggle to find many people who've used it in production. They finally moved from release candidates to a first stable version last week. However, it has been created by a whole bunch of extremely well-respected coders and if your project is across the middle-to-long term, you will see adoption of RobotLegs explode during the lifetime of your project. It is going to be what all the cool kids are using! :)

(I have no stake, other than having occasional communications with some of the authors via Twitter and across the blogosphere).

HTH

alecmce
+2  A: 

I used RobotLegs for a game that required integration with a few different backend services. One service gave me a multi-player lobby area to allow players to challenge each other, one handled the head-to-head gameplay after a challenge, and one allowed players to access information from their social network accounts.

From the beginning, I planned the game's architecture as if I were building a Rich Internet Application. The game itself was an implementation of a popular turn-based board game. Thinking about how to run a local game vs a network game definitely helped me stay on track with the MVC framework approach to game development. There was a ton of code that could be reused, and the difference between interpreting a local player clicking with their mouse versus receiving a message through the network to indicate that a remote player did something similar helped me see what logic simply couldn't be tied to the view at all. I was able to use models, commands, and mediators very smoothly, and in the end, it made the game's code more maintainable and easier to understand when I delivered it to my client.

I think most games will have a basic model that tracks the "board" whether it be pieces in a grid or enemy ships and asteroids out in space. Once you're thinking of the model as a separate entity from the view, it should be easier to imagine how player interactions through mouse and keyboard could trigger commands from controller to make changes to the model and notify the view of those changes. For some simple games, that might end up being a lot more work. For others, such as those where long-term maintenance or multiple input methods are required, it can save some headaches.

Let's think about the different views in a game for a second. Views can include a title screen, a settings/options screen, a multi-player lobby, high scores/leaderboard screen, and the main game itself (which could consist of many smaller views!). Many of these views can have models, like the list of high scores, the various settings (which should be shared between the options screen and the game views), the list of players waiting for a game, and the current state of the game, etc. By the way, need a way to save the game so that a player can restart where they left off? It's way easier to do that when the data is in a model and not tied directly to the view.

I think that too many Flash developers look at games as hugely different beasts from Rich Internet Applications. An MVC framework can be appropriate for a game, especially for multi-player and for games that you intend to iterate on over a longer period of time to add new content and features. The biggest challenge is making yourself remember the fact that cute, little furry critters running across your screen is just a visualization of data that might easily be displayed in a different way using DataGrid or a chart... though it may not be as fun to play with them that way!

joshtynjala
Great just what I wanted to hear! I was worried that my original approach of mvc for different screens then mvc for seperate entities in the screen was a little ott, especially being new to mvc in general. it's just getting my head around how mvc is applied to a game and I guess the rest (robotlegs) will fall in to place. Cheers for your post!