-
[AS3/F10]How to create HUD layer
As topic says, I'm trying to create HUD layer - a group of movie clips which are always on top of all other stuff, so a place where to put score, healthbar, ammo...The problem is that I don't know how to control the order of rendering or depth (Z-order). Any ideas?
Last edited by Joint; 08-12-2009 at 02:02 PM.
-
Pumpkin Carving 2008
What I normally do is create each "layer" of the game as its' own MC, and then create an object to hold that MC to interface with it. For a HUD layer, I'd do something like:
Code:
HUD = {};
HUD.clip = _root.createEmptyMovieClip("hud", _root.getNextHighestDepth());
HUD.score = something;
HUD.lives = somethingElse;
HUD.health = somethingElseElse;
Then you can interface directly with this clip when say, the player loses a life:
Code:
player.lives--;
HUD.lives.gotoAndStop(player.lives);
Using objects isn't probably the best way to keep things sorted. The main point here is that you're only worrying about the depth of one group of MC's; the layer clips. You will probably only have 5-6 different layers in a typical game. Then when you go to add clips to these layer MC's you don't have to worry about depth anymore.
The 'Boose':
ASUS Sabertooth P67 TUF
Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
8GB G.Skill Ripjaws 1600 DDR3
ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
New addition: OCZ Vertex 240GB SATA III SSD
WEI Score: 7.6
-
maybe an AS3 version, if I'm not asking too much?
-
Pumpkin Carving 2008
To quote the readme sticky:
Originally Posted by Squize
* Please use prefixes on your threads
Due to the fairly high volume of posts here we are currently making the move to putting a prefix on all our new threads.
This is to remove vague thread names, so everyone has an idea of what they are about to read before they click on it.
These are not set in stone, but here are some common ones as a rough guide:
[Disc]: ( Discussion )
If you have a burning topic you want feedback on or just want to get a debate going to get peoples views.
[Help]:
Just don't know where to start or what direction to go in with a project ?
[Problem]:
You've written your code, but for some reason it's just not working.
[Link]:
Found something that would be rude not to share ? Spread the word.
[Beta]:
Your game is almost there, just a couple of rough edges and / or you want people to highlight bugs for you.
[Complete]:
Show off that finished game to everyone
[Note]:
Found a Flash bug ? Read a good book ? Save people hunting around for the info and leave a note for everyone.
As well as using the prefixes, it helps everyone if you're thread has some meaning to it, eg
"[Problem]: Collisions not working"
is a million times better than...
"Help me..."
* Flash Version
If you're not using the latest Flash version, in order to get the most appropriate answer and not cause confusion, specify which version you're using. Flash 8 is the current version (as of October 2005), but for now, Flash MX 2004 is still widely used.
You may also specify the ActionScript and Flash Player version if needed.
Unfortunately, I do not code in AS3. Hope someone else answers your question. (The theory still applies, if you are using AS3 it couldn't be that hard to adapt it, could it?)
The 'Boose':
ASUS Sabertooth P67 TUF
Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
8GB G.Skill Ripjaws 1600 DDR3
ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
New addition: OCZ Vertex 240GB SATA III SSD
WEI Score: 7.6
-
Funkalicious
It's the order you attach children basicly. This is the same for AS2 and AS3. The latter children get placed on top of the previous ones.
Code:
var BackGround:MovieClip = new MovieClip()
var Actors:MovieClip = new MovieClip()
//
var HUD:MovieCLip = new MovieClip()
var Score:MovieClip = new ScoreClip()
var Lives:MovieClip = new LivesClip()
var Health:MovieClip = new HealthClip()
HUD.addChild(Score)
HUD.addChild(Lives)
HUD.addChild(Health)
//
addChild(BackGround)
addChild(Actors)
addChild(HUD)
-
instead of using addChild(Hud); use addChildAt(Hud, 0);
the second parameter is depth. higher depths are on top of lower depths.
-
Wait- what now?
Or,
PHP Code:
function foremost(obj:MovieClip) { obj.parent.setChildIndex(obj, obj.parent.numChildren-1); }
Use this function on the hud layer whenever you add a new child to the stage.
"I'd only told them the truth. Was that so selfish? Our integrity sells for so little, but it is all we really have. It is the very last inch of us, but within that inch, we are free."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|