A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: How can i make it so a cloned element come back if it leaves the screen?

  1. #1
    Senior Member
    Join Date
    Feb 2005
    Posts
    177

    How can i make it so a cloned element comes back if it leaves the screen?

    ok i have a cloned element in my star wars game called "fighter" as in the tie fighters. I have them moving and if you dont shoot them they leave the screen. How can i have it so that if they leave the screen, that they come back for you to try to shoot them again?

    thanks
    Last edited by sonic04; 06-24-2005 at 10:46 PM.

  2. #2
    Junior Member
    Join Date
    Jun 2005
    Posts
    2
    Oh my favorite movie is Star Wars! can you send me the game of you made and I want to play it. LoL. AIm = RomeoBlu2013 as possible.

  3. #3
    Senior Member
    Join Date
    May 2005
    Posts
    163
    The simplest things to use are the methods for boundary handling in 3DFA specifically (this is from right from help under element methods):

    .boundaryBounce () element will bounce off the sides of the screen
    .boundaryJump () element will jump to the opposite side of the screen
    .boundaryHide () element will be hidden when it travels off the screen

    I have included an example, if you are unsure on how to use these, of the jump method which sounds like what you are looking for.
    Attached Files Attached Files

  4. #4
    Senior Member
    Join Date
    Feb 2005
    Posts
    177

    ?

    ok thanks for the file, but in my game there is more than one fighter because it is cloned. The script i used to clone my element "fighter" is different than yours. it is:

    f = element ("fighter")


    fighter= new Array(num_fighter);
    for (i=0;i<num_fighter;i++) {
    fighter[i] = f.clone();
    fighter[i].x = 399+random(79);
    fighter[i].y = 60+random(250);
    fighter[i].acceleration.x = -(50);
    }
    }



    so how can i make it so that if the CLONED fighters leave the screen the CLONED fighters appear at the other side?

    thanks
    Last edited by sonic04; 06-30-2005 at 06:16 PM.

  5. #5
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Those methods don't work with clones obviously, there is a sample under simple that demonstrates how to do this. But it makes them bounce, take a look at it but what you want is to reappear. It is similar



    PHP Code:
    for (i=0;i<fighter.length;i++) {

    if (
    fighter[i].x>400){//assumes movie is 400 wide
      
    fighter[i].x=0//better to use the width of fighter 
    }


    of course you may need to check for x<0 and perhaps y as well but you get the idea I hope.

    Put this in a script element that runs every frame

  6. #6
    Senior Member
    Join Date
    Feb 2005
    Posts
    177
    ok thanks, but line four cant be resolved. My original starting place is at x = 675, so i entered that in but it still cant be resolved. What am i doing wrong?
    thanks
    Last edited by sonic04; 06-30-2005 at 09:30 PM.

  7. #7
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Quote Originally Posted by sonic04
    ok thanks, but line four cant be resolved. My original starting place is at x = 675, so i entered that in but it still cant be resolved. What am i doing wrong?
    thanks
    Check you code closely I just cut and pasted the above and just added
    fighter=new Array() in the start script and it work fine without error

  8. #8
    Senior Member
    Join Date
    Feb 2005
    Posts
    177
    ok i tried changing a few things but then screwd up some other things so i took out the script. This is what i had though,

    for (i=0;i<fighter.length;i++) {

    if (fighter[i].x>0
    fighter[i].x=600
    }

    }


    i thought the script would make it so that once my fighter reached the left hand side of the movie (x=0) that it would go back to the right hand side of the movie (x=600).

    i will add my file, though im no where near done with the game maybe u can still help me finish this script im having trouble with. I erased the scrip, but maybe u can help me with what i should put,

    thanks
    Attached Files Attached Files

  9. #9
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    for (i=0;i<fighter.length;i++) {

    if (fighter[i].x>0){
    fighter[i].x=600
    }

    }

  10. #10
    Senior Member
    Join Date
    Feb 2005
    Posts
    177
    uhh i dont know whats wrong, when i entered the script my clones lost there acceleration and didnt move at all.

    can u try looking at my file when u get a chance?

    thanks

  11. #11
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    few adjustments
    Attached Files Attached Files

  12. #12
    Senior Member
    Join Date
    Feb 2005
    Posts
    177
    ok thanks a lot

  13. #13
    Senior Member
    Join Date
    May 2005
    Posts
    163
    I know you have something that works from blanius but I wanted to show how it could be done using the 3DFA methods mentioned above. (At worst case you'll have more than 1 way to do the same thing).

    I just modified the for loop, from the original download, "Script 35" element to do a .boundaryJump() for each of the clones.
    Attached Files Attached Files

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