dcsimg
A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: Making The Largest Of A Duplicated Movie From Loop In Highest Level ????

  1. #1

    Making The Largest Of A Duplicated Movie From Loop In Highest Level ????


    I have created creatures that get closer with scaling then when reached a certain size jump out at you. this creature mc has been duplicated with a loop to produce 3 , all with random scale rates. in a variable called growth

    firstly how do I always make the largest on a higher level so it is in front of the smaller ones so it looks closer ?

    they are created in the main timeline with
    ------------

    for (i=1; i<3; i++) {
    evilbogey_mc.duplicateMovieClip("evilbogey_mc"+i, i);
    }

    for (n=4; n<7; n++) {
    microNinja.duplicateMovieClip("microNinja"+n, n);
    }

    -------
    -------------
    then have this on each Movieclip (evilbogey_mc and microNinja)
    --------------
    onClipEvent (load) {
    var attack = false;

    function reset() {
    this._x = (Math.random()*500);
    this._xscale = 0;
    this._yscale = 0;
    attack = false;
    growth = (Math.random(4)+1);
    this.gotoAndPlay("start");


    }
    reset();
    }
    onClipEvent (enterFrame) {
    this._xscale += growth;
    this._yscale += growth;
    _root.debug3 = growth;
    if (this._yscale>=80) {
    growth = 0;
    if (attack == false) {
    this.gotoAndPlay("attack");
    attack = true;
    }
    }
    }
    on (press) {
    this.gotoAndPlay("killed");
    _root.headshot3.start();

    }

    -----------------------
    this sets the scaling up etc
    SO i need to make the one growing fastest or the largest in FRONT all the time?????
    HOW DO I DO THIS Ive tried swapDepths

    Thanks in advance
    Dave Mattock
    dave@mattockgraphicdesign.com

  2. #2
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749

    swapDepths is right

    You need to build a sort function, this is not tested, but it has the basic idea (look in the array reference for more info. The sort function has to return -1 for less than, 0 for the same as and 1 for greater than.

    PHP Code:
    monsterarray = [];
    function 
    create_monster() {
        var 
    newmonster;
        
    // Whatever code you have eg
        
    monsterindex++;
        
    attachMovie("monster""monster"+monsterindexmonsterindex);
        
    newmonster this["monster"+monsterindex];
        
    // Whatever code you have
        // Whatever code you have
        // Whatever code you have
        // ...
        
    monsterarray.push(newmonster);
    }
    function 
    sort_monsters(ab) {
        var 
    samesize a._xscale == b._xscale;
        var 
    infront a._xscale>b._xscale;
        if (
    samesize) {
            return 
    0;
        } else {
            
    // infront true returns -1+2 = 1
            // infront false returns -1+0 = -1
            
    return -1+2*infront;
        }
    }
    function 
    sortmonsterdepths() {
        var 
    monsterdepth 50;
        
    monsterarray.sort(sort_monsters);
        for (var 
    0i<monsterarray.lengthi++) {
            
    monsterarray[i].swapDepths(monsterdepth+i);
        }


  3. #3

    thank you !

    Excllent, thanks for that Ill try and get my head round it and give it a go... Its a little bit Over my head but Ill go through it bit by bit.

    Does that mean I should'nt use my normal for loop to duplicate the MC and put an OnclipEvent.EnterFrame code on the clip... but do it via attaching the clip instead ?

    Many thanks
    Dave Mattock

  4. #4
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749
    To stop the monsters screwing around with each other, the swapDepths is best done from one place. The way I set it out above means you only need to use a single onEnterFrame to check all monster depths.

    PHP Code:
    onEnterFrame sortmonsterdepths

    For CREATING the monsters, do it however you feel like. You could easily use a for loop as follows:
    PHP Code:
    for( var i=0;i<20;i++) {
    create_monster();

    BTW, ideally, you would delete the monster from the array when he gets squished. It will probably work without doing that, but it just leaves some loose ends.

  5. #5
    Flash Initiate StuartW's Avatar
    Join Date
    Jul 2000
    Location
    The Metaverse
    Posts
    504
    Wicked.

    Don't mind if I do.

    Dave - I understand all of that, so if you need further assistance give us a shout.

    Stu

  6. #6

    WICKED

    THANK YOU ALL !!
    AlsoGaiusCoffey, thanks for the speedy responses
    and Stu yeah Id love to run through this with ya. Ill call tommorrow and drop the CD up

  7. #7
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749
    So I didn't do much work today ...

    And I can't draw for toffee ...

    And this is probably nothing like what you are trying to do ...

    And is probably not a lot of use to you ...

    But it was fun playing around!

  8. #8
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749
    This is a bit more like something like a game.

  9. #9

  10. #10
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749

    Grrr. Bug.

    The delete function was being silly when run in a browser: solution = make "i" into "var i".

  11. #11
    I really must thank you for going to so much trouble... Im at intermediate level and half understood this, but some went way over my head.

    But after a friend looking throught the code you uploaded aswell and going through it bit by bit , line by line..I am beginning to get there... Ive never used prototype before and love the way that if I want to add different and more baddies I can just add a repeat a few lines of the code... wicked

    I could nt download the fla on a mac and had to use a PC for some reason ?

    Once again thanks very much...
    On another note Im have trouble temporarily stopping all the baddies timeline while the baddie that jumps out plays its death blood animation then starts all again

    what is your background, Im adesigner learing code. I suppose you come from a programming background

    THANKS AGAIN !!!!!!!!!!!!!

  12. #12
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749
    thank you for going to so much trouble
    Glad to hear its of use. To be honest, I'd never had an opportunity to use the sort function before so I got involved with finding a way to test it and ended up getting carried away. Purely selfish motives on my part!

    I suppose you come from a programming background
    It must be my high-quality graphics that gave me away.
    A bit of everything, but my first love would be relational database followed by (and soon to be overtaken by) object programming.

    plays its death blood animation
    I am getting scared. You will have to let me see the finished game.

    temporarily stopping all the baddies
    Everything I can think of is a bit kludgey. The easiest to implement is probably this:
    PHP Code:
    Monster_MC.prototype.setup = function() {
        
    this._x = (Math.random()*550);
        
    this._y = (Math.random()*300);
        
    this._xscale this._yscale=MONSTERBABY;
        
    this.growth = (Math.random(MONSTERGROWTH)+1);
        
    this.gotoAndPlay("start");
        
    this.onEnterFrame this.advancing_monster;
    };
    Monster_MC.prototype.advancing_monster = function() {
        if (!
    paused) {
            
    this.growme();
        }
    }; 
    You need to then create a paused variable on the main timeline which an attacking monster sets.

  13. #13
    Hi, and once again thanks !!

    Ive put all that code which was in you fla example you uploaded and changed the Monster_MC name to bogey_mc just so I remember as I intend to have many monsters so used a descriptive name... anyway ... eventually all seems to work well.

    The only problem I have is it doesent trace the baddies like it does in yours in the output window

    Ive been going through it word by word as I dont just want to use the code but understand it fully, I read about using prototypes etc.
    Its more complex the way you have done it but I can see its very clever and useful as I suppose I only need to dupliacte a few lines to add a completely different baddie in it!

    Im going to try and randomise it a little so If I dupliacte 2 ninjas and 2 bogeys after a certain amount of time 1,2, or 3 more my appear, then onto a different level

    Ill let you know when its finished... be a while yet ,have you got an email address ? then I can upload it and let you check it out

    thanks again
    dave@mattockgraphicdesign.com
    check out http://www.mattockgraphicdesign.com if you get time, Youll see Im more of a designer than coder

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