A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: duplicate hittest

  1. #1
    Senior Member
    Join Date
    Apr 2000
    Posts
    136
    i have a colission detection between a ball and a square with the hit test metheod.
    i want to duplicate the square many times, is there a way to make the coilloision work with out writing a diffrent code for each square?

  2. #2
    Member
    Join Date
    Jul 2000
    Posts
    56

    yes it's possible:
    use these object actions on your prototype movieclip which u want to duplicate:

    on clipEvent (enterFrame) {

    if this.hitTest("ballMC") {

    some_actions;

    }


    }

  3. #3
    Senior Member
    Join Date
    Aug 2000
    Posts
    134

    Insted try this...

    selcuk ,
    In your script you must put the instant names of all instances of squares in the if statement method and I thing is not so easy to combine.
    Insted ,shamway , you may try to make one Script with variables,and to use call action evry time there is hitTest!
    Good luck

  4. #4
    Senior Member
    Join Date
    Apr 2000
    Posts
    136
    i dont know what is the call action, but i found a way around it.
    insted writing the code in the ball, i write it in the square and use if.this then i can duplicate the square as many times as i want and it works.
    but thank's

  5. #5
    Banned By GMF Wannabe Gambini's Avatar
    Join Date
    Oct 2000
    Posts
    976

    Problem with hitTest

    I have had a similar problem and I still can't get it to work...

    I've got the same thing on screen - one square and a rectangle. when the rectangle collides with the square (hitTest) it's fine...however if I duplicate the square over and over again - it fails to work even though the actionscript is EXACTLY the same.

    I'm using the (this.hitTest(_MCname) routine but it won't work.....please help!

  6. #6
    Member
    Join Date
    Jul 2000
    Posts
    56

    Cow Icon

    Oh sorry,
    I thought that there was just one square and several balls in the movie; it seems it's the vice versa...

    it is also posiible to use functions also;


  7. #7
    Member
    Join Date
    Jul 2000
    Posts
    56

    Re: Problem with hitTest

    Originally posted by Gambini
    I have had a similar problem and I still can't get it to work...

    I've got the same thing on screen - one square and a rectangle. when the rectangle collides with the square (hitTest) it's fine...however if I duplicate the square over and over again - it fails to work even though the actionscript is EXACTLY the same.

    I'm using the (this.hitTest(_MCname) routine but it won't work.....please help!
    ------------------------

    1. it may be possible that you put your hittest action on the rectangle and duplicating the square... hittest action should belong to the duplicated object... I tried it in a dxball-like game and it worked fine... If this doesn't work try attachMovie instead duplicating, I think it's a better method. There is a wonderful example of this in the sample files in flash5 which is named Mosquito Killer

    2. if you're duplicating both of your objects you must use arrays and loops so that u could test wheter each object hit the one of the other or not... This might work slowlier depending on the number and complexity of the duplicated objects.


  8. #8
    Senior Member
    Join Date
    Apr 2000
    Posts
    136
    hi gambini, make sure to give each square a diffrent insant name.
    actually what i'm doing is a dx-ball like game,selcuk could you tell me how you did the falling parts from the squares?
    thnk's

  9. #9
    Member
    Join Date
    Jul 2000
    Posts
    56
    Originally posted by shamway
    hi gambini, make sure to give each square a diffrent insant name.
    actually what i'm doing is a dx-ball like game,selcuk could you tell me how you did the falling parts from the squares?
    thnk's
    what I did was not exactly dxball, but there was a ball which destroyed square-shaped objects around etc. but I think I could do falling parts also; u might attach to each square a random distribution for what will happen when the collison happens: for example, each time the collision occurs AND your random(100) is smaller then 20 (which is a prob. of 20%) try attachMovie("particle", "particle" add particleCount, particleCount) etc. on your particles write a code like this:

    on clipEvent (enterFrame) {
    this._x=this._x+somefunction(); ' a function to determine the horizontal move of the particle
    this._y=this._y+gravityFunction(); ' or just a gravity variable, say g

    '..
    'collision detection with the racket
    '...

    if this._y>lowerLimit {
    this.removeMovie();


    }
    }
    }

    it might require many other details depending on your aim and design... but I would prefer attachMovie.

    one other way might be preparing maps for each level instead of randomizing... if you're using attachMovie and duplicate, u might create a dummy, nonvisible element where each particle should start to detect wheter the collison occured...

  10. #10
    Senior Member
    Join Date
    Apr 2000
    Posts
    136
    could you explain or direct me to a place i could learn this attachMovie, since i don't understand it.


    Originally posted by selcuk
    [QUOTEone other way might be preparing maps for each level instead of randomizing... if you're using attachMovie and duplicate, u might create a dummy, nonvisible element where each particle should start to detect wheter the collison occured...
    what did you mean by this?
    thank's

  11. #11
    Member
    Join Date
    Jul 2000
    Posts
    56
    Originally posted by shamway
    could you explain or direct me to a place i could learn this attachMovie, since i don't understand it.


    Originally posted by selcuk
    [QUOTEone other way might be preparing maps for each level instead of randomizing... if you're using attachMovie and duplicate, u might create a dummy, nonvisible element where each particle should start to detect wheter the collison occured...
    what did you mean by this?
    thank's
    The best example about attachMovie action comes with the Flash 5, in sample files... Mosquito Killer, attachMovie does almost the same thing with duplicateMovie, however it pulls the object from the library, not from the movie.

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