Flash Advisor logo
:: Desktop Shortcut
:: Flash Help
Advice from Experts

Closed Thread
Results 1 to 2 of 2
  1. #1

    Default Collision Detection?? PLS HELP!!



    I need to make a flash game for college, and my enemies need to kill my player dude. I have all the code working, key movement etc, the only thing I need now is how to make my player die!

    Also a bonus would be if someone could help me get my special items to disappear when my player collects them...


    pls pls pls pls help!!!

  2. # ADS
    Join Date
    Always
    Posts
    Many
     
  3. #2
    Join Date
    May 2004
    Location
    U.S.A.
    Posts
    2,890

    Default

    Hi,

    Collision detection is achieved with the hitTest method...

    this.onEnterFrame=function(){
    if(mcA.hitTest(mcB)){
    trace("collision");
    }
    }

    However, the hitTest only test for the graphics bounding box so irregular shapes other than a square will create some problems. For a game with multiple enemies, it would prob be best to store the enemies in an array and use a for loop to hitTest...

    myEnemies=["enemy0","enemy1","enemy2"]

    Now you can employ a hitTest against a hero movieclip with something like...

    this.onEnterFrame=function(){
    for(i=0;i<myEnemies.length;i++){
    if(heroMC.hitTest(myEnemies[i]){
    trace("Collision detected");
    }
    }
    }

    As for collecting objects, you would prob use a hitTest with a custom function for either fading the alpha or toggleing the visible property of a movieclip...

    Alpha fade function...

    function fadeObject(fTarget){
    this.onEnterFrame=function(){
    fTarget._alpha -=10;
    if(fTarget._alpha<=0){
    delete this.onEnterFrame;
    }
    }
    }
    //Usage.....functionName(targetObject)
    fadeObject(coin);

    Another option is simply to toggle the coin mc's visible property...

    if...hitTest...
    coin._visible =false;

    hope it helps
    A mind once stretched by a new idea never regains its original dimensions.
    - Oliver Wendell Holmes

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Collision Crisis
    By Gamerkd16 in forum Flash Scripting
    Replies: 2
    Last Post: 03-28-2006, 09:46 PM
  2. multiple collision problem
    By malmatate in forum Games
    Replies: 2
    Last Post: 12-11-2005, 05:42 PM
  3. INTERNET CONNECTION DETECTION
    By jgaffney in forum Newbies
    Replies: 1
    Last Post: 09-02-2003, 07:30 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Sponsors
Create Speaking Characters for your website and Flash movies. 15 Day Free Trial