A Flash Developer Resource Site

Page 4 of 11 FirstFirst 12345678 ... LastLast
Results 61 to 80 of 215

Thread: The elusive hitTest explained

  1. #61
    There Were No Good Names Left
    Join Date
    Dec 2002
    Location
    Edge of a building
    Posts
    118

    Sorry

    Um that was a typo. I didn't actually write that in the fla. but, I figured out the problem. There was a line of code in the timeline that I missed. I had been looking within the movieclip, but it was on the outside. it works now. Thanks for your help though!

  2. #62
    Da' newby
    Join Date
    Sep 2002
    Posts
    37
    hey im having a problem with my enemy dieing when he is hit by my "player" here is the code
    onClipEvent(load){
    _x = Math.round(_x/5)*5;
    _y = Math.round(_y/5)*5;
    }

    onClipEvent(enterFrame){
    dx = _parent.player._x - _x; // distance between them


    d = Math.sqrt(dx*dx+dy*dy);

    // I take _width as being the distance between the two clip's centers
    if(d > 20 && d < 250){
    // Find angle to travel: (180/Math.PI) converts radians to degrees
    _rotation = Math.atan2(dx, -dy)*(359/Math.PI);
    // Travel that way
    _x -= Math.sin(_rotation)*20; // 5 is speed

    }
    if(_x-25 > _root.player._x+15){
    _x-=5;
    } else {
    this.gotoAndStop("attack")
    }
    } \\BELOW IS WHERE IM HAVING THE PROBLEM AND IT'S PROBABLY EASY TO FIX
    onClipEvent(enterFrame) {
    if(hitTest(_root.windmillring)) {
    gotoAndPlay ("die");
    }

    }
    i have the "die" movieclip in the enemy and when he hits the windmillring i want it to play "die"

    any help would be great
    thanks
    AOL: rubaduckyromeo
    MSN: adamthedunstar@hotmail.com
    YAHOO: rubaduckyromeo
    http://www.nebo.edu/phs/index.htm
    RubaduckyRomeo

  3. #63
    .: Weirded Out :. The_Xell's Avatar
    Join Date
    Nov 2002
    Location
    Under the table and dreaming...
    Posts
    802
    I was bored so i made this rather cool little game!
    Remember those games with the metal thing that was looped around wire, which u had to follow?

    Well, using some nice shapeflag hit test, i made it - so if your abit miffed by it all, download this .fla!

    I hope this is the right place, im sure it will help someone!
    Attached Files Attached Files

  4. #64
    Ihoss
    Guest
    I have a problem in my Shoot-down-enemy-space-ships game. if i have 10 space ships flying down the screen, and a gun which shoots bullets, how can i quikly find out if the ship has been hit. this is the code that i have used so far:

    Code:
    for( i; i<11; i++){
    if(_root.ship.i.hitTest(this._x,this._x,true)){
    gotoAndPlay("explode"):
    }
    }
    the problem is to make the if() code use the variable i. can anyonehelp me?

  5. #65
    Pan Troglodyte Erectus
    Join Date
    Jan 2002
    Location
    South Africa
    Posts
    92
    if your ships are named "1", "2", and "3" you can do this:

    Code:
    for( i; i<11; i++){
      if(_root.ship[i].hitTest(this._x,this._x,true)){
        gotoAndPlay("explode"):
      }
    }
    not too sure how you named your ships. If they were named "ship1", "ship2", etc. do this:

    Code:
    for( i; i<11; i++){
      if(_root["ship"+i].hitTest(this._x,this._x,true)){
        gotoAndPlay("explode"):
      }
    }
    Last edited by Bixarrio; 01-20-2003 at 09:40 AM.

  6. #66
    PWFilms
    Guest
    Heya, quick question...

    So heres the set up---
    There's a movie clip as the mouse called mouse1, and inside that, there's a dynamic text box called mousehit. There is another movie clip on the screen, a painting, and I want it so that when the mouse is over the painting, the dynamic text box says "Painting"

    Yeesh...

  7. #67
    .: Weirded Out :. The_Xell's Avatar
    Join Date
    Nov 2002
    Location
    Under the table and dreaming...
    Posts
    802
    ok, the directory of the dynamic text box is:

    _root.mouse1.mousehit

    On the little painting, make it an MC, and insert this code:

    Code:
    OnClipEvent(enterframe){
    if(this.hittest(_root.mouse1)){
    _root.mouse1.mousehit = "painting"
    {
    {
    This should work...... my syntax maybe wrongish (just edit it in advanced mode)

    Good luck!

  8. #68
    PWFilms
    Guest
    Ah haha! Thats what I was doing wrong... Thanks!

  9. #69
    .: Weirded Out :. The_Xell's Avatar
    Join Date
    Nov 2002
    Location
    Under the table and dreaming...
    Posts
    802
    no problem, i do suggest you start a new thread so people will see it!

    Good luck with what that code was for!

  10. #70
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    i've got this problem and i don't know how to fix it, my guy keeps sticking to the walls

    http://www32.brinkster.com/mrmalee/test.html
    Last edited by mr_malee; 02-05-2003 at 12:40 AM.
    lather yourself up with soap - soap arcade

  11. #71
    SaphuA mosterdfles_flash's Avatar
    Join Date
    Jan 2002
    Location
    Tha Couch
    Posts
    935

    :)

    That depends on what your code is and what you want it to be

    Show the code you have now...

    Or:
    My favorite... wich I first got of Magnetos (I guess) and wich is used a lot (I guess)

    onClipEvent(load){
    jumping = false;
    velY = 0;
    }
    onClipEvent(enterFrame){
    //-->
    //Walking code goes here
    //<--
    //
    //-->
    //Jumping code
    if(Key.isDown(Key.UP)){
    jumping = true;
    velY = -8;
    }
    if(jumping == true){
    _y += velY
    velY++;
    }
    //<--
    //
    //-->
    //HitTest
    if(_root.ground.hitTest(_x, _y, true)){
    while(_root.ground.hitTest(_x, _y, true)){
    _y--;
    }
    jumping = false;
    velY = 0;
    } else {
    jumping = true;
    }
    //<--
    }

    I hope this i the right code cuz I just typed without testing... but it should be working

    Greetz,
    SaphuA
    'How Art Is The Visual While We’re Artificial…'

    Mail & MSN
    My Not Finisched Page!
    Nick: SaphuA

  12. #72
    Junior Member
    Join Date
    Feb 2003
    Location
    IREALAND
    Posts
    5
    Can someone help me I want it so that if i collide with something then after a few seconds it'll go to another frame

  13. #73
    Ihoss
    Guest
    can someone tell me if there is anything wrong with this code?

    Code:
    setProperty (laser, _y, getProperty(laser, _y)-5);
    if (_root.mgame.mHero.Zaber.hitTest(this._x, this._y, true)) {
    	tellTarget (_root.mgame.mHero) {
    		gotoAndStop (1);
    	}
    }

  14. #74
    .: Weirded Out :. The_Xell's Avatar
    Join Date
    Nov 2002
    Location
    Under the table and dreaming...
    Posts
    802
    Do you think you could give us some more information?
    Visually there are no errors, but then again, it depends in what context you use the AS!

    I hope i can help, but i need more information

  15. #75
    foul-mouthed chucklehead
    Join Date
    Feb 2003
    Location
    inches away from you, in the 4th dimension....
    Posts
    198

    hitTest problem (go figure)

    alright, alright. I figured instead of starting a new thread, i would just post here, since my problem is a hitTest problem.

    I printed David Doull's tutorial here in Flashkit on making a spaceship side scroller. I went through it a few months ago, and got the game to work....for the most part. But i lost the files and decided to redo it. Here is my problem:

    I have the baddies coded to hitTest for the "spaceship". If so, then the movie goes to frame 3 "gameOver".

    that didn't work. So, i put the hitTest on the spaceship to test against the enemy. That didn't work.

    I even tried changing the gotoAndStop from "gameOver" to frame number 3. Still, no dice. And this worked before! Maybe its a stupid mistake im overlooking? here is my code:

    Code:
    //enemy test for spaceship
           
           if(this.hitTest(_root.spaceship)){
             _root.gotoAndStop("gameOver");
           }
    Code:
    //spaceship test for enemy
           
           if(this.hitTest(_root["enemy"+i])){
            _root.gotoAndStop("gameOver");
           }
    I know this code is right. They are both under onClipEvent(enterFrame) actions. But it still doesn't work!
    Furthermore, i know that all the movie clips are named properly in the code, and the frame label is not misspelled....i quadruple checked all of this!!
    Last edited by chuckles; 02-25-2003 at 03:28 PM.

  16. #76

    Accual collision!!! how?

    Originally posted by flashGaul
    that worked, that really worked.

    thx edmack that was gr8 help.

    this is what I tried and got it. The important thing is that I have totally eluded the hitTest function of flash.

    onClipEvent (enterFrame) {
    x = _x-_root.two._x;
    y = _y-_root.two._y;
    h = Math.sqrt((x*x)+(y*y));
    rad = _width/2;
    radTwo = _root.two._width/2;
    sumRad = rad+radTwo;
    if (sumRad>=h) {
    trace("yes");
    }
    }
    onClipEvent(load){
    startDrag("", true);
    }

    two is the other movie clip on the stage.

    Infact I am working on a pool game with this help I can really move ahead. I will start posting threads based on this.

    thx again.
    This maybe workes fine with balls but if you want to check irregular shaped Mc's for collision... like this two:

    I don't want them to react when their bounding boxes collide...

    or...



    This is the collision I'm looking for:


    Is there a way?

  17. #77

    Sorry!

    Didn't read all messages before posting... (only read the first page. didn't see that there was more).
    The other posts answered my question... that it's not possible.

  18. #78
    foul-mouthed chucklehead
    Join Date
    Feb 2003
    Location
    inches away from you, in the 4th dimension....
    Posts
    198
    um....are you sure you read right?

    I thought it was possible. (this.hitTest(x,y,shapeflag))

  19. #79

    nope!

    the collision I mensioned should look like homeDrone says on page 3 in this thred...

    anyMovieClip.hitTest(target, shapeFlag);

    the hitTest you mension only checks one specific point.

  20. #80
    Member
    Join Date
    Feb 2003
    Location
    Canada
    Posts
    61
    Okay, here is my code for the hittest in my game. The problem is it checks the bounding box and not the actual image shape. So I get collisions when it does not look like I should. How would I fix this.

    Oh and the link to the game (not finished) is
    http://www.sfhq.net/sfhq/game.swf
    and http://www.sfhq.net/sfhq/game.fla

    onClipEvent (enterFrame) {
    if (this.hitTest(_root.sovereign)) {
    shipVel=0
    if (_root.shield>0) {
    _root.rshield.moveMovieClip (rshield);
    _root.rshield._x = this._x;
    _root.rshield._y = this._y;
    _root.rshield._rotation = this._rotation;
    _root.shield -= 1;
    }if (_root.shield<1) {
    _root.life -= 1;
    _root.rshield.moveMovieClip (rshield);
    _root.rshield._x = _root.non._x;
    _root.rshield._y = _root.non._y;
    _root.rshield._rotation = _root.non._rotation;
    }
    }}

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