A Flash Developer Resource Site

Results 1 to 19 of 19

Thread: swapDepths()

  1. #1
    Junior Member
    Join Date
    Aug 2003
    Location
    Coimbra - Portugal
    Posts
    7

    swapDepths()

    Hi
    My function to update depths don't work.
    Can you help me?...
    Rui
    Attached Files Attached Files

  2. #2
    Junior Member
    Join Date
    Aug 2003
    Location
    Coimbra - Portugal
    Posts
    7

    swapDepths

    Sorry i forgot «3dfa 4 rel 4»
    Rui

  3. #3
    A Senior Newbie - How Odd ForumNewbie's Avatar
    Join Date
    Mar 2003
    Posts
    590
    Hi There,

    This is a real nice script.

    I think the main problem here is that swapDepths just swaps the depths of elements, rather than taking into account which one was in front to start with.

    So it looks to me as if the script is continually swapping them in both senses, and the end result is that they always stay where they are.

    Attachment deleted because it was no help

    I tried to do the same with pins in a 10 pin bowling game, but found the only way was to destroy the clone and recreate the clone each time there was a collision to be sure it was in the foreground.

    If anyone has a better idea, I'd love to hear it.

    ForumNewbie
    Last edited by ForumNewbie; 11-16-2003 at 09:24 AM.
    Please note that my domain has changed to http://www.morganmultinational.com

  4. #4
    Senior Member
    Join Date
    Nov 2003
    Location
    Coimbra - Portugal
    Posts
    139

    Re: swapDepths

    I'm ruipaiva
    I have had problems in my pc and i was forced to do another registration here.
    Yes, your solution probably can solve the problem.
    I go to try change depths only when there is a collision.
    Thanks a lot.
    Rui

  5. #5
    A Senior Newbie - How Odd ForumNewbie's Avatar
    Join Date
    Mar 2003
    Posts
    590
    Hi Ruipava,

    Just to let you know, and maybe save you some time, I tried to add collision detection to your animation, but it still didn't work quite right.

    I think that's because you never know how many times the script will run during the collision. As a result, it may swap once, twice, (or more times) during the collision, and end up the wrong way round again.

    You'll need to add something into the script that makes sure the swapping process only runs the script once per collision.

    Also, I think you'll need to make sure the cloned elements are created in a particular sequence, so that the furthest back one is created first, and the closest to the front is created last. This makes sure they're in the right sequence before they start swapping.
    I'm not 100% sure on that last point, but it certainly seemed to work best when I did that to it.

    Best of luck,

    ForumNewbie.
    Please note that my domain has changed to http://www.morganmultinational.com

  6. #6
    Senior Member
    Join Date
    Nov 2003
    Location
    Coimbra - Portugal
    Posts
    139

    swapDepths

    Hi ForumNewbie:
    Yes, you have reason... That's true...
    It's necessary swapDepth when collidge, stop script for these two objects, still work for anothers, check when first two objects end collition.
    Probably with a flag or each one object, -1 in colliting, 0 end collition... Who check when end collition?...
    Seems complicated, isn't it?...
    So, i'm trying...
    Thank you very much for colaboration.
    PS - i have another problem is my mind, imagine a cube menu, each one face is a button, this cube move arround 3d axes like this script...
    What do you think about?...
    Rui Paiva

  7. #7
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    what you do is set a flag variable hascollided=false

    then in your collision test

    you do

    PHP Code:
    if (element1.collideRect (element2) && !hascollided){
      
    hascollided=true;
      
    //do your collision code here should only happen the first time 
      //they collide as we have set hascollided to true now

    }else{if !element1.collideRect (element2) && hascollided){
    //no longer colliding then reset hascollided
       
    hascollided=false;


    since your doing a bunch of objects give them a property like myobjects[x].hasCollided=false in a loop then check that in above script

  8. #8
    A Senior Newbie - How Odd ForumNewbie's Avatar
    Join Date
    Mar 2003
    Posts
    590

    Cracked It !!

    Well, that was a challenge !!


    I decided the whole logic of the swapping wasn't going to work, so I tried another method. I created 2 arrays, to indicate which ball should have been at what depth based on it's scale parameter, and which it actually was at, based on it's starting depth.

    Unfortunately, it seems to cause 3dfa a problem due to some extreme looping, but it works in the browser.

    I've attached it thus.

    I'm off to lie down in a darkened room.


    ForumNewbie.
    Attached Files Attached Files
    Please note that my domain has changed to http://www.morganmultinational.com

  9. #9
    Senior Member
    Join Date
    Nov 2003
    Location
    Coimbra - Portugal
    Posts
    139

    uffff........

    Hi ForumNewbie:
    I had problems with your solution.
    So, i decided try another way.
    It's explained on movie file.
    We are close...
    Rui Paiva
    Last edited by rui_eduardo; 09-29-2008 at 11:31 AM.

  10. #10
    Senior Member
    Join Date
    Nov 2003
    Location
    Coimbra - Portugal
    Posts
    139

    posible solutions

    hi
    i have been thinking about swapDepths because my solution, attached file on last message don't work quit well.
    one option is clone 16 times, clones 8 till 15 are a copy of 0 to 7.
    in case of clone 0 have z = 90 and is colliding with clone 5 with z = 40, then as this have a depth more elevated, we hide clone 0 and show clone 8, when collision end, we hide 8 and show again clone 0.
    but this duplicate pc work, because is moving clones 0 - 7 and 8 - 15, at the same time.
    another option is probably clone only when start collision and destroy it after end collission, in this case, the number of duplicated clones are small and of course then small will be the pc work.
    i don't know, it's very complicated...
    bibi
    Rui Paiva

  11. #11
    A Senior Newbie - How Odd ForumNewbie's Avatar
    Join Date
    Mar 2003
    Posts
    590
    Hi Rui Pava,

    I assume when you said you had a problem with my method, it was because it doesn't work well in 3dfa. That's a 3dfa problem with loops, but the code does work. There may be a more efficient way to do it, which perhaps someone could help us with.

    I hope you don't mind, but I posted a version of the file here so you can see it really does work in the browser.
    Demo of your animation working properly

    I think that getting the code in this example to run more efficiently might be more effective than the cloning method. Perhaps we can find out how to disable the 3dfa 'breaking out of loop, >100000 lines' feature which might sort out the problem in 3dfa.

    ForumNewbie.
    Please note that my domain has changed to http://www.morganmultinational.com

  12. #12
    Senior Member
    Join Date
    Nov 2003
    Location
    Coimbra - Portugal
    Posts
    139

    your demo

    Hi ForumNewbie:
    Your demo work really nice.
    You got the goal.
    I presume then this demo work just with same code you attached.
    I go try export it to html to check.
    Really spectacular... Nice work.
    Rui Paiva

  13. #13
    Senior Member
    Join Date
    Nov 2003
    Location
    Coimbra - Portugal
    Posts
    139

    i got

    Hi ForumNewbie:

    I got a function to set right depth and work well in several kind of 3d animations.

    I attach here.

    Bibi
    Rui Paiva
    Last edited by rui_eduardo; 09-29-2008 at 11:30 AM.

  14. #14
    A Senior Newbie - How Odd ForumNewbie's Avatar
    Join Date
    Mar 2003
    Posts
    590

    Ahah

    Excellent work Rui,

    Although the ball demo still doesn't appear right in 3dfa, it doesn't crash it like mine did, and it too works in the browser.

    Well done

    ForumNewbie.
    Last edited by ForumNewbie; 11-26-2003 at 04:02 PM.
    Please note that my domain has changed to http://www.morganmultinational.com

  15. #15
    Member
    Join Date
    Aug 2002
    Location
    Switzerland
    Posts
    71

    clones

    hi there

    i have a problem quite similar to this one.
    i like to have a collision detection to make clones disappear, but of some reason this won't work. any idea, how i can solve this?

    thanks and have a nice night

    bruno
    Bruno

    www.tonetube.ch

  16. #16
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    You could use my distance check for collision and that will always work for clones.
    Or if they are circular use the Circle collision which uses the distance method

    PHP Code:

    */
    //*************************************
    //simple distance test
    //*************************************
    function distance(element1,element2)
        {
        
    a=element1.element2.x;
        
    b=element1.element2.y;
        return 
    sqrt (a*a+b*b);
        }
        
    //*************************************
    //Circle Collide
    //*************************************
        
    function C_collide(element1,element2)
        {
        
    //get width of both elements
        
    width1=(element1.getBounds().xMax-element1.getBounds().xMin)-6
        width2
    =(element2.getBounds().xMax-element2.getBounds().xMin)-6
        
    //get distance 
        
    a=element1.element2.x;
        
    b=element1.element2.y;
        
    distsqrt (a*a+b*b);
        
    //account for different sizes
        
    width=(width1/2)+(width2/2);
        
    //check distance and size
        
        //return t/f
        
    return dist<=width
        


  17. #17
    Member
    Join Date
    Aug 2002
    Location
    Switzerland
    Posts
    71
    hm, it doesn't work. maybe i have overseen something.
    here my code:
    PHP Code:
    schranke element ("Paint Schranke");

    for (
    i=0;i<ball_array.length;i++){
        if (
    distance(ball_array[i],schranke) <0){
            
    ball_array[i].hide();}

    /***********Distance********************/
    /********** Function from Bret**********/
    function distance(element1,element2){
        
    a=element1.position.element2.position.x;
        
    b=element1.position.element2.position.y;
        return 
    sqrt (a*a+b*b);

    schranke is an object in the middle of the screen, where the clones should not be visible.

    greetings
    Bruno

    www.tonetube.ch

  18. #18
    Member
    Join Date
    Aug 2002
    Location
    Switzerland
    Posts
    71
    btw i'm wondering if clones are able to follow around the mouse in a random manner.
    any suggestions?
    Bruno

    www.tonetube.ch

  19. #19
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Originally posted by chriegszocker
    hm, it doesn't work. maybe i have overseen something.
    here my code:
    PHP Code:
    schranke element ("Paint Schranke");

    for (
    i=0;i<ball_array.length;i++){
        if (
    distance(ball_array[i],schranke) <0){
            
    ball_array[i].hide();}

    /***********Distance********************/
    /********** Function from Bret**********/
    function distance(element1,element2){
        
    a=element1.position.element2.position.x;
        
    b=element1.position.element2.position.y;
        return 
    sqrt (a*a+b*b);

    schranke is an object in the middle of the screen, where the clones should not be visible.

    greetings
    I doubt the distance between them is ever <0
    Think about it.

    If you want collision use the difference of size of the elements as your test not <0, if you really want them EXACTLY on each other then use ==0

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