dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Collisions

  1. #1
    Junior Member
    Join Date
    Nov 2005
    Posts
    1

    Collisions

    well i'm trying to put collisions on a randomly generated background from a collection of movie clips. i have several layers on randomly genearted background and they have paralex scrolling on them. i need my character to have collisions only with one of the layers. I can't assign instance names to my movie clips and use hitTest it doesn't wokr. what else can i do? i have the file available it's just a pretty big one.

  2. #2
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167
    I dont see why using a hitTest doesnt work. Whatever is on your layer, select it and convert it into a movieclip

    Then put the code on it :

    code:
    onClipEvent(enterFrame){
    if(this.hitTest(_root.character)){
    //Something happens
    }
    }


  3. #3
    Junior Member
    Join Date
    Nov 2005
    Posts
    21
    I currently have 2 movie clips, and a variable. On the stage, the first mc is called player_mc, and the second is key_mc. The variable is key=1 on a layer on my timeline.
    What would I write in key_mc, so that when player_mc comes in contact with it, key_mc is removed completely from the stage, and the variable key then changes to a value of 2?

    So far this is what I have but it does not seem to work (this code is placed in key_mc):
    Code:
    onClipEvent (enterFrame) {
         if (_root.player_mc.hitTest (_x, _y, true)) {
              _root.key = 2;
              removeMovieClip(_root.key_mc);
         }
    }
    What is wrong with it?

  4. #4
    Senior Member Bernz's Avatar
    Join Date
    Jun 2005
    Location
    Mid-Eastern U.S.
    Posts
    161
    removeMovieClip() only works for movieClips that were added to the stage using the attachMovie() function.


    For what you want, you'll have to get creative. First, use
    code:
    this._visible=false;

    This will make the user unable to see the movieclip, or use any buttons in it.


    Then, you'll have to find a way of disabling any script you might have in that movieclip. You could override the eventhandlers you'd made.
    code:
    this.onEnterFrame=null;

    However, to use this, you'd have to have used eventhandlers, not the onClipEvent(enterFrame){ code.
    If not, I suggest changing a boolean to false, and putting all code in an if() statement that uses that boolean to determine if that code should be run.

  5. #5
    Senior Member
    Join Date
    Oct 2003
    Posts
    1,354
    Im not familair with your use of hitTest(_x,_y,true)? Did you get this from somewhere?

    (_root.player_mc.hitTest (_x, _y, true)
    You will want to conduct a hitTest between key_mc and player_mc:


    Code:
    onClipEvent (enterFrame) {
         if (_root.key_mc.hitTest (_root.player_mc)) {
              _root.key = 2;
              _root.key_mc.gotoAndPlay(20);
         }
    }
    Where frame 20 would be an empty frame with no objects on it. Any script on frames 1 to 19 would ofcourse no longer be running. However any action on the object (and not in its timeline) would still be active.

    Since this script is attached to the key_mc, you can also reference it as "this". The following code is using Bernz's visible = false, instead of moving the playhead. I don't know if one has advantages over the other.

    Code:
    onClipEvent (enterFrame) {
         if (this.hitTest (_root.player_mc)) {
              _root.key = 2;
              this._visible=false; 
         }
    }

  6. #6
    Junior Member
    Join Date
    Nov 2005
    Posts
    21
    Ok. Thanx. I found the hitTest I used on one of the tutorials in here actually. It worked for some reason when the visibility command but not with the variables I put in. Maybe this will work differently. Thank you, I will post in here if I continue to have problems.

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