开发者

Dynamic UI window drawing in Flash?

开发者 https://www.devze.com 2023-03-16 13:44 出处:网络
Wasn\'t sure if this question belongs here, but I\'ll try. So I\'m about to move my project from Director | Shockwave Player (if you ever heard of these) to Flash Player for numerous reasons and while

Wasn't sure if this question belongs here, but I'll try. So I'm about to move my project from Director | Shockwave Player (if you ever heard of these) to Flash Player for numerous reasons and while I'm thinking how to better start off I got a question which really made me wonder. To the point.

Currently in Director each game window in the user interface (like small alerts or large windows with lot of elements in them) is drawn upon need - meaning that the actual window's graphical image is being put together from configuration (all sorts of properties like width, height and all elements and their properties) from numerous pieces of graphics (e.g. window background is made from 9 small pieces like the 4 corners, 4 middle pieces between corners for dynamic width and height and 1 central piece to fill the window) and then added to stage. This approach makes it easy to edit each graphical element without having to redraw the actual windows and everything in them if we would like to change the color scheme or improve something in a element. It also saves the resources as windows are be开发者_如何学Pythoning drawn only when requested.

Now I got to figure out if it's worth writing such code in Flash too as opposite to just creating all the windows and placing them in the library and adding to stage when they are requested. What do you think? Is it worth writing such implementation?


IMO, it depends on 1) How comfortable you are with Flash's drawing API / graphics class, and 2) How flexible each window/dialog needs to be.

If it's easier to just throw them together as static objects -- and if they don't necessarily need the flexibility to change dimensions/style much (can you count on one hand how many times they've needed to change since it was originally done in Director many years ago?), it's obviously easier to do this than going through the time/energy to recreate them dynamically, especially if you're not very comfortable with Flash's drawing API.

That said, a lot can be accomplished dynamically with Flash's drawing API, so if you have the time/interest I'd certainly suggest digging in and doing it the "right" way if you want to familiarize yourself with the drawing API.

My method for doing this sort of thing usually goes like this:

  • Create a separate class that extends Sprite/MovieClip; something like 'Dialog.as'.
  • Create public init(), show(), and hide() methods, and a private build() method.
  • init() is called just once upon initialization of your app, and takes some global parameters to hold on to internally (padding, colors, etc).
  • show() takes an argument of either text (a String), or even a Sprite/MovieClip -- whatever it is you want to show in this dialog. When called (when you want to spawn a window), it uses this -- plus whatever init parameters were originally passed in during init() -- to draw itself, and then unhides itself (tween the .alpha property, or simply set the .visible property).
  • When you want to close the dialog, make sure to invoke the hide() method, which first hides itself, and then cleans up whatever was created (removing listeners, etc) so that the next time it is called upon it can draw itself fresh.

It might also make sense to pass into this object a reference to the Stage (in the original init() call), so that it can center and size itself accordingly on the stage, and also addChild itself to the top of the display list so that it's always above everything else.

I hope this helps.


If is 2D you can check this:

http://pushbuttonengine.com/

if is 3D you can start here:

http://alternativaplatform.com/en/alternativa3d/

I can suggest you also Unity3D but this is outside of flash

Hope it helps

0

精彩评论

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