A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [F8] Making Duplicated MCs Interact

  1. #1
    Junior Member
    Join Date
    Jan 2008
    Posts
    11

    [F8] Making Duplicated MCs Interact

    Hey, can someone tell me how to detect numerous duplicated movie clips with hitTest? I don't mean simultaneously, but in such a way that you can differentiate between a target and, say, its 5 other duplicates.

    In my game, the main character can fire bullets at enemies, and the bullets are deleted after they cause damage to the enemy. Here is the main character movie clip's code for firing the bullets when a button is pressed:

    _root.bullet.duplicateMovieClip("bullet"+i, i);
    eval("_root.bullet" + i)._x = this._x;
    eval("_root.bullet" + i)._y = this._y;
    i++;
    if(i >= 50) {
    i = 1;
    }

    and here is the code for the bullet:

    onClipEvent(enterFrame) {
    this._x += 15;
    if (this.hitTest(_root.enemy)) {
    _root.enemy._hp -= 10;
    this.removeMovieClip();
    }
    }

    Everything works fine up to this point. Each duplicated bullet has its own individual code which is the same as the original bullet movie clip. They all cause damage and are removed on contact with the enemy's movie clip. But, at the start of the Flash movie I duplicate the Enemy mc however many times with the same code that duplicated the bullets:

    _root.enemy.duplicateMovieClip("enemy"+1, 1);
    eval("_root.enemy" + 1)._x = whatever x value
    eval("_root.enemy" + 1)._y = whatever y value

    I identify each duplicate with eval("_root.enemy" + i), where "i" stands for some integer, and place each one at a different (x,y) coordinate. But, I don't know how to make each different Bullet duplicate respond correctly to each different Enemy duplicate with hitTest. Do I need to set up some kind of array, or just test for contact between each different bullet and enemy duplicates for every frame (because that's WAY more work than I was planning to do)?

    Any help would be greatly appreciated!

  2. #2
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    what you have:
    - is an ancient copyPaste flash 5 (Flash 10 is already comming) code style.[dumping code on movieClips is usually something like that]

    what you need:
    - is a decent understanding of arrays, functions and loops
    - to NOT put your code on MovieClips at all

    anyway it might be a smart move putting all cores into individual functions - and having just 1 main loop, I´ll try to write up an example

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