Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411582 Posts in 69386 Topics- by 58445 Members - Latest Member: Mansreign

May 06, 2024, 03:20:18 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Stay on top
Pages: [1]
Print
Author Topic: Stay on top  (Read 1387 times)
commodore
Level 0
**



View Profile
« on: November 15, 2009, 07:50:19 AM »

How do I make a displayobject stay on top of everything else at all times?
Logged
handCraftedRadio
The Ultimate Samurai
Level 10
*



View Profile WWW
« Reply #1 on: November 15, 2009, 07:58:43 AM »

draw it last.

you are probably going to have to make your question more specific.
Logged

dbb
Level 4
****



View Profile WWW
« Reply #2 on: November 15, 2009, 08:08:00 AM »

Um... it would depend what language you're coding in, wouldn't it?

If you're using Game Maker, just set its depth to something like -1,000,000 and make sure nothing else has a depth less than this.
Logged

commodore
Level 0
**



View Profile
« Reply #3 on: November 15, 2009, 08:17:23 AM »

I'm so sorry =D I'm using actionscript 3. I meant to include the Flash message icon but I managed to forget it =P.
Logged
BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #4 on: November 15, 2009, 08:56:08 AM »

AS3 doesn't use depths, you have to insert objects into the display list at the appropriate postion.

Because this is book keeping pain, I like to use nested displayobjectcontainer to layer stuff, and don't bother with the sort order inside each "layer". So I have:
Code:
HUD
  Score
  Lives
  etc
Foreground
  FG Clip1
  FG Clip2
Main Layer
  All Game objects

Or something like that.
Logged
hatu
Level 2
**



View Profile
« Reply #5 on: November 15, 2009, 01:07:43 PM »

I like to use this little badboy myself, just to make it much clearer what's happening.

Code:
public function bringToFront(_child:DisplayObject, _parent:DisplayObjectContainer):void
{
_parent.setChildIndex(_child, _parent.numChildren-1);
}
Logged
Glaiel-Gamer
Guest
« Reply #6 on: November 15, 2009, 01:18:09 PM »

I like to use this little badboy myself, just to make it much clearer what's happening.

Code:
public function bringToFront(_child:DisplayObject, _parent:DisplayObjectContainer):void
{
_parent.setChildIndex(_child, _parent.numChildren-1);
}

Code:
public function bringToFront(_child:DisplayObject):void
{
_child.parent.setChildIndex(_child, _child.parent.numChildren-1);
}

i've never used prototype but this might work too
Code:
DisplayObject.prototype.bringToFront = function():void
{
this.parent.setChildIndex(this, this.parent.numChildren-1);
}
Logged
bateleur
Level 10
*****



View Profile
« Reply #7 on: November 15, 2009, 11:52:14 PM »

How do I make a displayobject stay on top of everything else at all times?

Notwithstanding the workarounds above, the literal answer to this question is that you can't, because it's always possible some later operation will put something in front.

Use of nested DisplayObjectContainers can solve these sorts of problems in practice, but there's no catch-all solution.
Logged

commodore
Level 0
**



View Profile
« Reply #8 on: November 16, 2009, 04:36:57 AM »

Thanks for your help guys!
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic