dcsimg
A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: question about cloning

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

    question about cloning

    ok heres my scenario. Right now I have a two level space shooting game which should have more levels when im done with it. Right now i have the first level complete. There are a few astroids and once they are destroyed you beat the first level. But in the second level i want the cloned astroids i used from the last, but this time I want a little more, maybe 7 astroids.

    How can i make it so that in "Scene 2" where my level2 comes into play, how can i make it that there is 7 cloned "astroid" elements on the screen. I already have cloned "astroid" element in my "Scene1" which there is 5, how can i make it that in scene2 there is 7?

    thanks you
    Last edited by sonic04; 03-23-2005 at 06:09 PM.

  2. #2
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    I'm assuming you used an array of clones, Just reset the array an make new clones.

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

    ok

    ok well here's the problem, i'm not exactly sure how to do that.

    heres my code :

    //variables
    num_astroids = 7;

    a = element ("astroid");

    astroids = new Array(num_astroids);
    for (i=0;i<num_astroids;i++) {
    astroids[i].createMovie();
    astroids[i] = a.clone();
    //position somewhere randomly on screen
    astroids[i].x = 400+random(80);
    astroids[i].y = 60+random(250);
    astroids[i].acceleration.x = -random(20);

    }

    this is my clone code for level one, what should i change to it to make it account to level two? In level one i have 5 astroids but for level 2 i have 7 thats why i changed the varriables. Ok so would i use the starting script for my level two child movie to make more astroids, and if so, what should i change to this code that i would put in my level two to get me more astroids??

    thanks

    thank you

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

    ok

    if anyone that wants to help needs a file i got one. Just preview the game in your browser for it to work

    thanks
    Attached Files Attached Files

  5. #5
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244

    Re: ok

    Clear the array

    astroids.clear()
    Then just do it again with new num_astroids

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

    soo

    soo in my level two child movie starting scrip, would i put:

    astroids.clear

    a = element ("astroid");

    astroids = new Array(num_astroids);
    for (i=0;i<num_astroids;i++) {
    astroids[i].createMovie();
    astroids[i] = a.clone();
    astroids[i].x = 400+random(80);
    astroids[i].y = 60+random(250);
    astroids[i].acceleration.x = -random(20);

    }
    Well this wont work, so what should i put, sorry im just a little confused here.


    thanks
    Last edited by sonic04; 03-24-2005 at 10:43 PM.

  7. #7
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    a = element ("astroid");

    astroids = new Array(num_astroids);
    leave this part out of the second level.

    That should work. If you hid the array elements you should make sure you show() them in you loop here as well

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

    ok

    ok but the new 7 astroids keep comming up in level one... even though the code is in level two. How can i hide the newer astroids ?from level one?

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

    A little guidance ...

    Hi Sonic,

    Having looked at your movie, I think there may be some confusion with how the scripts are running. The starting script runs once when the main movie starts to execute. If you change parameters elsewhere in the movie, then that script won't execute again unless you do something specific to instruct it to do so.

    Also, I'm afraid I couldn't really work out how the scene's and sub-movies were hanging together, so I trimmed it down to something a little simpler, with just 1 scene. I left the 'levelone' movie present because it contains all the game elements, but really it's just a generic element to keep the others tidy, and doesn't really do that much.
    You can still have multiple levels with a method like this, but they're just handled slightly differently. There may be a better way to do this using scene's and child movie's, but I tend to find script a little easier. I guess it's personal preference.

    So: What did I do to make it work :

    Firstly, I chopped out the unnecessary scene and child movie for level 2.
    I changed the starting script so that the 'initialisation' of all the bad guys were done in a function. This means you can call that function at any time later on in the movie.
    I set a variable to indicate what level the player is on, and set a 'switch/case' condition to set how many bad guys should appear on each level.
    I cut out the 3 statements about 'createMovie' in the starting script, because I couldn't see what they were doing. That may just be my lack of knowledge there, but it worked fine without the statements, and got less error messages on compiling.

    Take a look and see what you think. It still crashes in the preview mode, because you have some scripting in there it doesn't like that much, but it seems to work 'more or less' in the browser.

    Hope I haven't hacked the game about too much for you!

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

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

    ok thanks

    ok thanks morgan, thanks a lot.

    I was just having so much trouble working with multiple levels but now you have helped me and I should be closed to finish on my game.

    One problem is that the more astroids there is the more slower the game goes, but this is ok for I have dial up and if people play this game that have roadrunner and dsl, stuff like that, it should work fine.

    Once again thanks so much.

    jaron

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

    by the way

    by the way, thanks for breaking down the code and showing exactly what everything did. Now i have a better feel for what you did.

    thanks again

    jaron

  12. #12
    A Senior Newbie - How Odd ForumNewbie's Avatar
    Join Date
    Mar 2003
    Posts
    590
    You're very welcome !

    I'm not sure how clone's work exactly, but I don't think that the use of many clones will affect the loading time, since they're cloned as they're played, and aren't loaded as separate objects. Also - The compiled size of the game so far is only about 4k, so you're not going to have to worry for a little while yet.

    The problem will be the running time. I would think you ought to be OK with 10's of clones, but I think it would get quite slow with hundreds or thousands, or if you put very complex graphics or animations into each one.

    Incidentally - In case I forgot to mention: I added a bit of script in the initialising function to allow you to select how many of each bad guy each level has. I hope this explains how to get multiple different, and potentially quite complex levels out of 1 relatively simple movie.

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

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