Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Every time you generate a car in your <code>animateCars()</code> function, you could iterate through all the children and put the buildings above the cars, but that's a little tedious and unnecessary (and not very efficient).</p> <p>This would be a much better method:</p> <pre><code>//create a container for the cars var carContainer:Sprite = new Sprite(); addChild(carContainer); //create a container for the buildings var buildingContainer:Sprite = new Sprite(); addChild(buildingContainer); </code></pre> <p>Since you added <code>buildingContainer</code> after <code>carContainer</code>, it will always be on top (including everything you put in it)</p> <p>So now your <code>animateCars</code> method:</p> <pre><code>public function animateCars() { CarMC = Random_Car(); carContainer.addChild(CarMC); if (CarLeft) { CarMC.x = 0; CarMC.y = 245; MoveCar = new Tween(CarMC,"x",None.easeNone,-60,900,12,true); } else { CarMC.x = 0; CarMC.y = 258; CarMC.scaleX *= -1; MoveCar = new Tween(CarMC,"x",None.easeNone,800,-260,12,true); } MoveCar.addEventListener(TweenEvent.MOTION_FINISH, CarFinished); MoveCar.start(); } </code></pre> <p>Then your <code>carFinished</code> method:</p> <pre><code>function CarFinished(e:TweenEvent):void { carContainer.removeChild((e.currentTarget as Tween).obj as Random_Car); } </code></pre> <p>Then in your <code>addBuilding</code> method, change <code>addChildAt(Building,numChildren);</code> to:</p> <pre><code>buildingContainer.addChild(Building); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload