views:

39

answers:

1

I'm writing an AS3/Flex4 game engine, and I want to have a base class for any item that can be put in the scenegraph. I wondered if extending UIComponent is the right approach, but there seems to be a whole lot of internal stuff there I don't want to get tangled up in... if possible I'd have some separation between my engine and the Flex framework. And I'm not sure if UIComponent adds overhead?

My renderable base can do fairly arbitrary things but for now consists of drawing simple shapes like lines and other primitives.

What might make a decent architecture? And also, many game engines have a "render" method to redraw the whole scene... but I imagine in a Flex app I should play with the DisplayObjectContainer or Canvas, rather than roll my own?

+3  A: 

If you're making a game engine I'd advise you to stay well away from the Flex classes. They're made to be skinnable, extensible and generic. Neither of which make them especially snappy performance wise.

Go with the most bare bone class you can get away with, in this case Sprite seems like the best choice.

grapefrukt
What about DisplayObject?
John
@John. You can't implement DisplayObject (it's not an interface) and you can't extend it either: it's not marked final but it behaves as if it were final and abstract; you can't instatiate it directly and you can subclass it directly, or at runtime your constructor will throw an ArgumentError; this is due to an ugly hack in the display list API, but that's the way it is. So, I'd say, go with Sprite.
Juan Pablo Califano
+1. Don't go the Flex route for a game engine. There are a ton of things you won't need but would add a heavy cost in performance (and download time in many cases). Also, most (all?) flash games don't use Flex, so these games'd have to add an indirect (and probably unwanted) dependency if they are to use your engine.
Juan Pablo Califano
You +1 your own comment?! Anyhow, does Flex _really_ add overhead if you only use it for certain things like GUI? You can have an AS3-only Flex project but without using Flex how do you suggest I _do_ write it? CS3/4 are not proper programming tools, so can you clarify? You can still do some low-level stuff in Flex so I'm not sure what the problem is exactly?
John
OK, so DisplayObject is a bit _too_ low-level unless we're really wanting to push the limits. It's actually vector graphics I'm doing so perhaps Shape is better, I'm still refreshing my memory on the differences between all these classes.
John
@John. No, I'm not that full of myself! I +1 grapefrukt's answer. Yes, Flex does a lot of stuff for you automatically, like managing layouts and other stuff, which is nice, but that takes resources and doesn't scale well (at least in a game, where usually you kind of need to optimize heavilly. Also, referencing even the simplest flex compenents pull a lot of stuff on your swf (unless the framework code is cache through swz, but I'm not sure about the specific, really); try doing something like displaying an alert and you'll see your swf grow like 200 Kb)
Juan Pablo Califano
@John. So, it's not that if you make a Flex project you *can't go low-level*. You can, but you've already added a lot of stuff on top of that. In most apps this is ok and makes your like easier, but in general, in a game this is too much.
Juan Pablo Califano
So how _do_ you create a game in AS3 then... what tool lets you use a programming IDE rather than one for artists, like CS3? I've seen 2 MMOs (one using 3D graphics) written using Flex, but they implemented their own rendering. I'm not too convinced all the other stuff adds performance overhead if you don't use it though... SWF size yes that's true.
John
There's a lot of confusion out there between the Flex framework and the IDE , it's totally possible to use FlashBuilder (ex Flex IDE ) to develop pure AS3 project.
PatrickS
@John. I think you're confusing Flex (the framework) with the Flex SDK (a set of compilers, tools and utilities) and Flex/Flash Builder (an Eclipse based IDE). I don't work with Flex (the framework) but I do work on Flex Builder (which uses the Flex SDK). I've also used other IDEs like FlashDevelop, Sepy(in the old days), etc. I don't work on games usually, but I have done some and it's totally possible to avoid the Flash IDE for coding (and the only sane way if you ask me). So, again, I'm not saying use the Flash IDE; I just think Flex (the framework) is not a good choice here, but that's me.
Juan Pablo Califano
OK, I should have know that clarification but got a bit confused, been a while since I used it. Yep, you can use the IDE for a Flex-free project. Most of the code would not involve Flex anyway so I can probably remove it later - I think the main point of not deriving from UIComponent essentially answers my question. `(Flex)Sprite` appears to be the normal choice (there's another problem but that's a separate question). If you're bothered about the rep, write up your comments into an answer and I'll accept it...
John
@John. No problem, the terminology leads to confusion easily. I don't care too much about rep and honestly see no point in adding an answer duplicating what I already wrote if your question has alreayd been answered, as you say. But thanks for the offer, anyway ;)
Juan Pablo Califano