A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: duplicated movie clip hit test detection

  1. #1
    suvat cobhc's Avatar
    Join Date
    Jan 2004
    Location
    england
    Posts
    156

    duplicated movie clip hit test detection

    Hey this movie clip duplicates every time space is hit (i e a new bullet is attached and fired)
    How do i detect if this hits an enemy lets say?
    the original movie clip is called "missile" but the hit test only detects the original not the new ones that are added. How can i solve this?
    do duplicated movie clips have a special instance name like "missile2" for example?
    thanks
    rory

    code:

    onClipEvent (enterFrame) {
    if (_root.ammomode == 1){ if (Key.isDown(Key.SPACE)){
    _root.ammo-=5;
    missile++;
    _root.missile.duplicateMovieClip("missile"+missile , missile);
    _root["missile"+missile]._visible = true;
    }else{
    if (_root.ammomode == 0){
    if (Key.isDown(Key.SPACE)){
    missile++;
    _root.missile.duplicateMovieClip("missile"+missile , missile);
    _root["missile"+missile]._visible = true;
    }
    }
    }
    }
    }


  2. #2
    Death to anime
    Join Date
    Mar 2006
    Location
    Holland, MI
    Posts
    32

    Array

    Make the bullets into an array. Once they are in array, use this code.

    Code:
    for(j in Arrayname){
    this[Arrayname[j]]._x+=5
    }
    Code:
    onClipEvent(load){
    trace("I am a geek")
    }

  3. #3
    suvat cobhc's Avatar
    Join Date
    Jan 2004
    Location
    england
    Posts
    156
    ok ive since found out that it adds a value to the original name of the mc everytime you duplicate it (ie "missile" will go to "missile2" then "missile3"...and so on)
    so if i were to make an array would i not have to punch in the value of evey attached mc that may ever come into existance?
    Is there not a piece of action script that will represent any real number like that weird r in maths text?
    than my hit test code could be as simple as:
    code:

    onClipEvent(load){
    Dead = false;
    p = "code for any real number here"
    }
    onClipEvent(enterFrame){
    if(this.hitTest(_root["missile"+p])){
    with(_root.baddy){
    Dead = true;
    }
    }
    }


    is that possible?
    thanks
    rory

  4. #4
    Script kiddie VENGEANCE MX's Avatar
    Join Date
    Jun 2004
    Location
    England
    Posts
    2,590
    Eep, big problem here - the movie clip you're duplicating, and the counter variable you're concatenating to the duplicate's name, both have the name 'missile'; I'm surprised you're even able to create them successfully in the first place...
    http://www.birchlabs.co.uk/
    You know you want to.

  5. #5
    suvat cobhc's Avatar
    Join Date
    Jan 2004
    Location
    england
    Posts
    156
    if i change the name of the counter variable it makes no difference to the hit test tho, i will still have the same problem but my new mc's will have a different counter variable wont i?
    is it possible to represent any number in flash?
    rory

  6. #6
    Junior Member
    Join Date
    Oct 2008
    Posts
    3
    Quote Originally Posted by cornyanimation
    Make the bullets into an array. Once they are in array, use this code.

    Code:
    for(j in Arrayname){
    this[Arrayname[j]]._x+=5
    }
    Is "j" the equivalent of the variable "missile"?

  7. #7
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    j is string representing names in Arrayname. this[Arrayname[j]] will give access to each of the missiles.

  8. #8
    Junior Member
    Join Date
    Oct 2008
    Posts
    3

    Arrow

    Thanks, I've managed to hitTest detect duplicates now as long as the hitTest only involves one duplicated movieClip.
    However I'm still stuck on how to have a duplicateMovieClip detect another duplicateMovieClip.

    for (var y:String in list){
    _root[list[y]].onEnterFrame = function(){
    for (var f:String in list2){
    if(_root[list[y]].hitTest(_root[list2[f]])){
    _root[list2[f]].removeMovieClip()
    _root[list[y]].removeMovieClip()

    }}}}

    I can't get the hitTest to work in this, is it becuase I used a for...in loop inside of another for...in loop?

  9. #9
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Try this way
    PHP Code:
    _root.onEnterFrame = function() {
        for (var 
    y:String in list){
            for (var 
    f:String in list2){ 
                if (
    _root[list[y]].hitTest(_root[list2[f]])) {
                    
    _root[list2[f]].removeMovieClip();
                    
    _root[list[y]].removeMovieClip();
            
                }
            }
        }


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