A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Creating layers in AS3

  1. #1
    The Cheeze to Your Macaroni ColbyCheeze's Avatar
    Join Date
    Dec 2007
    Location
    Texas
    Posts
    244

    Creating layers in AS3

    Okay I haven't had to deal with this problem until now...but I was wondering how the hell you can manage entity depth in AS3.

    With AS2 I would just set all of my BG objects to a low depth range, and all of my players units and what not at a higher depth range.

    With AS3 there doesn't seem to be any way to do this, and I am having big problems with things like my turrets on ships showing up UNDERNEATH them sometimes...its all random things just get placed all over the place.

    I'm not really sure how to keep everything where it needs to be. Anybody else know how to solve this issue?

  2. #2
    Senior Member rachil0's Avatar
    Join Date
    Jul 2007
    Location
    Columbus, OH.
    Posts
    465
    The way I'd do it is use separate container sprites for capital ships vs. their turrets. Then composite them into your document class in back to front order:

    Code:
    public class MainDocument extends Sprite
      {
      public function MainDocument()
        {
        var shipsprite : Sprite = new Sprite();
        shipsprite.addChild( capitalShip1.sprite );
    
        var turretsprite : Sprite = new Sprite();
        for ( t=0; t < capitalShip1.turrets.length; t++ ) 
          turretsprite.addChild( capitalShip1.turrets[t].sprite );
      
        addChild(shipSprite);
        addChild(turretSprite);
        } 
      }

  3. #3
    Senior Member
    Join Date
    Mar 2008
    Posts
    301
    This post confuses me.

    Depth seems like a piece of cake in AS3.

    Am I missing something?

    addChildAt(), setChildIndex(), swapChildren(), swapChildrenAt()...

    If they're all in the same sprite,

    ship.parent.setChildIndex(ship,0);

    turret.parent.setChildIndex(turret,turret.parent.n umChildren-1);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center