开发者

Flex Games: Using Canvas Versus UIComponent?

For developing simple games with the Flex SDK, what are the consequences of using a Canvas object, versus a UIComponent object, as a drawing surface? Are there performance issues with either one? Are the methods generally the same? Searching around, it seems that most sample code I've found uses UIComponent. Is this just customary, or are there reasons?

I already know one odd difference - I had developed a simple Pong game using:

    public class MyGameCanvas extends UIComponent

and then decided to replace UIComponent with Canvas. This caused the line to fail:

addChild(paddle);

After spending too many hours searching, I finally found that a Canvas object requires:

rawChildren.addChild(paddle);

due to the inheritance chain of objects, Sprites being higher than Canvas.

But that doesn't seem like a reason to prefer one class to another. Are there any specific reasons? Thanks.

Update: Okay, I guess Canvas is out, and UIComponent is in. The only reason I even tried a Canvas object is the name. I mean, it's a Canvas - isn't that where you're supposed to do drawing? :)

So the second question that has popped up is about using the Flex SDK (and I don't know if this should be a totally new question, or here is okay).

However, I have to confirm something, being new to Flex and the various terminology. I'm presuming that people mean I should not be using MXML for games, when they said Flex SDK. Since I thought the Flex SDK was what provided the compiler that generates .swf files. Otherwise, where/how would I even compile AS3?

Assuming that's the case, then my que开发者_JAVA技巧stion would be about the suitability of using both MXML and AS3 for (simple) games. Based on what I've read about both, it seemed like the intended use of them was MXML for the interface elements, and AS3 for everything else. Is the overhead that bad for MXML?

John C>


I think there is no point at all to use flex sdk to develop a game. Flex SDK has been designed with application development in mind so you shouldn't use it to make games.

Do you have specific reasons to use it instead of a plain AS3 project?


Canvas has a bunch of extra layout code, plus scrollbars. It's definitely heavier than UIComponent alone. Also, it's important to know that Canvas requires all children to be subclasses of UIComponent. Using rawChildren to add non UIComponent is a hack unless you're building some sort of "chrome" for a Flex container (scrollbars on Canvas and the border/background in Panel).

I agree with PeZ, though. The Flex framework probably isn't the right choice for a game. Unless you have a game UI with things like DataGrids, Trees, Charts, etc., you can get a smaller and more optimized SWF without Flex.


If you dont need the additional stuff in canvas, like the scrollbars, that's clearly a reason to prefer UIComponent. Canvas is just an heavier object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜