A Flash Developer Resource Site

Results 1 to 4 of 4
  1. #1
    Junior Member
    Join Date
    Jul 2007

    resolved change depths in as3

    im trying to change depths of sprites that makes an elliptical movement.

    to make some perspective i scaled the sprites according to their y position and im trying to change their depths dynamically.

    As i expected swapDepths is no longer on AS3 so i tried to use setChildrenIndex() method, as adobe recommends. So the problem is that the index that i need to pass must be in range of the stage number of children. so i cant pass just a Math.floor() of the y position of the sprites, cause it throws an error.

    my pain is finding a way to calculate the correct depth of each sprite according to its y position

    now ive got something like this on my onEnterFrame handler

    for (i=0;i<sprites.length;i++) 
    	// first define the angle of each element 
    	sprites[i]._angle += speed;
    	// use sine and cosine to set the x and y position of each element, multiply by the radius factor and add the centerX value
    	sprites[i].x = Math.cos(sprites[i]._angle) * radiusX + centerX;
    	sprites[i].y = Math.sin(sprites[i]._angle) * radiusY + centerY;
    	// scale the sprites acoording to it's y position to create an illusion of some perstpective
    	s = sprites[i].y / (radiusY + centerY);
    	sprites[i].scaleY = sprites[i].scaleX = s;				
    	sprites[i].alpha = s + 0.3;
    	depth = ???;
    	stage.setChildIndex(sprites[i], depth);
    im trying to find a way to calculate the correct index (or depth)...

    i imagine something like this (but not exactly this)

    Math.floor(stage.numChildren / radiusY * sprites[i].y)

    but is not good

    is there an easy way to do it?


  2. #2
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    San Francisco, CA (USA)

  3. #3
    Will moderate for beer
    Join Date
    Apr 2007
    Austin, TX
    You should be able to use swapChildren, if you have a reference to two sprites that you want in reverse order.

  4. #4
    Junior Member
    Join Date
    Jul 2007
    hi guys,
    problem solved.
    thanks a lot to you both :-)

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

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.