A Flash Developer Resource Site

Page 5 of 11 FirstFirst 123456789 ... LastLast
Results 81 to 100 of 215

Thread: The elusive hitTest explained

  1. #81
    OffTheHorseCEO RegalKnight's Avatar
    Join Date
    Jun 2002
    Location
    Who said fallin off of a horse couldn't be an inspiration
    Posts
    138
    hi i need to know if my code only needs minor tweaking or if i should scrap it and completely over haul it. i want the tank to slow to a stop, and for the rumble to stop or at least lower in volume when the movement key is released. i cant get the wall collision straight

    keys are:

    player 1
    up arrow move forward
    down arrow move back
    left&right arrow rotate tank
    V & B rotate turret




    player 2
    move forward 8
    move back 5
    rotate tank 4&6
    rotate turret 7&9


    hey what do you think of the tank design?

    Well thanks for any help and also thanks to someone whose name i cant remember for giving me the code i already have used.
    Martin
    Attached Files Attached Files
    Last edited by RegalKnight; 03-05-2003 at 02:03 AM.
    BLING!

  2. #82
    Senior Member Penleeki's Avatar
    Join Date
    Mar 2003
    Location
    England
    Posts
    223
    Does anyone know if using hitTest with bounding boxes is less or more cpu intensive than writing your own function to do the same thing?
    I'm just wondering which is "better".

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

    :)

    The bounding boxes will be faster then writing a WHOLE function, although I don't think it will be a big difference...
    But you don't need a function for the hittest the:
    Code:
    if(mc.hitTest(_x, _y, true)){
    works very well
    'How Art Is The Visual While We’re Artificial…'

    Mail & MSN
    My Not Finisched Page!
    Nick: SaphuA

  4. #84
    leight.com.au leight's Avatar
    Join Date
    Sep 2002
    Location
    australia
    Posts
    1,437
    hi guys,
    i have been hearing interesting things with this hitTest. ive also tried to put empty mc's on the corners of the car (or tank im my case). this is what ive added into the tank code:
    Code:
        // hitTest with the rocks
        if (_root.tank.boundary.hitTest(_root.land)) {
            speed *= -.5;
        }
    y doesnt that work - it goes into like the centre of the tank still:S thanks for your help...
    Attached Files Attached Files

  5. #85
    Member
    Join Date
    Feb 2003
    Posts
    96

    ?

    Heyleighton can you put your fla tanks engine in flash 5 format? Please

    Thanks
    Matt

  6. #86
    leight.com.au leight's Avatar
    Join Date
    Sep 2002
    Location
    australia
    Posts
    1,437
    it is in flash 5 format... okay ill try again here it is matey...
    Attached Files Attached Files

  7. #87
    Ihoss
    Guest
    i am testing a newcool game kinda like snake. in the game you are suposed to catch all the red balls but you always leave a grey wall behind you, and if you hit it, you die!!! uses a whole lot of hittests. i just learned that if you gave two movieclips the same instance name ("wall" in my case) and you try to hittest another mc to them, it wont work, not as:
    Code:
    //this is in the "wall" mc
    if(this.hitTest(ship){
    //something
    }
    or:
    Code:
    //this is in the "ship" mc
    if(this.hitTest(wall){
    //something
    }
    youll find it on my website soon...

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

    :)

    Yeah that's right...

    MC,s on the same lvl never can have the same instance name...
    'How Art Is The Visual While We’re Artificial…'

    Mail & MSN
    My Not Finisched Page!
    Nick: SaphuA

  9. #89
    leight.com.au leight's Avatar
    Join Date
    Sep 2002
    Location
    australia
    Posts
    1,437
    does ne1 know y it doesnt work??? or cant u download the file???

  10. #90
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650
    I want to know how to make a health bar go down on hit.

    I can make one with numbers, like 100hp if hit, then -10.. now 90.

    but I need one witha graphic bar...

    I saw a tut somewhere before...

  11. #91
    Illuminatus! fospher.com's Avatar
    Join Date
    Jan 2002
    Location
    5th Dimension
    Posts
    2,185
    a tut? here's a tut to you, from me.

    1. make a bar and give it the instance name healthBar
    2. put in this code
    onClipEvent(load) {
    _root.healthBar._width=100
    }
    onClipEvent(enterFrame) {
    if (enemy attacks you, whatever happens - put in the code here) {
    _root.healthBar._width-=10
    }
    if (_root.healthBar._width<=0){
    you die
    }
    }

  12. #92
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650
    Cool. that wasn't so complicated . Thanks.

  13. #93
    Junior Member
    Join Date
    Apr 2001
    Posts
    5

    Question about hit area and slopes

    I've gone through the messages in this thread and I don't think that there was anything that specifically helped me with this, so I thought that I would ask in case anyone could help me!

    Essentially, I want to have the player control an object that will follow a sloped track when they press the right arrow key (a roller coaster), but the track is random. They would be able to jump up off of the track briefly, and set back down. Having a character run along a straight area is easy, but what about slopes?

    Thanks! =^i^=
    =^i~= --x

  14. #94
    Ihoss
    Guest
    ironclaw: remember to put the box which will be the health bar on the side of the centerpoint, or else its width will be decreased from both sides (towards the center point).
    Takysa: can you upload the file or give a better description, as i didnt understand what u meant.

  15. #95
    Amiga freak Ironclaw's Avatar
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    1,650
    Thanks, Ihoss, but I already knew that

  16. #96
    Junior Member
    Join Date
    Apr 2001
    Posts
    5
    Sorry!

    What I mean is that I want the movie clip to travel along the shape of the track, like when you're on a rollercoaster. So, rather than just changing the x axis of the player if he's walking along a flat surface, I'm changing the y as well to correspond with the shape of the track. They go from left to right, with dips and crests along the way. However, I don't know how to best tackle this, because the track is not going to be one single movie clip; it will have sections that are random so that the track is never the same.

    If I can get a visual for what I want to do, I'll post it.
    =^i~= --x

  17. #97
    Ihoss
    Guest
    there are two ways to do that (which i know of):
    the graphical: you can put the track inside another mc, and then hittest it that way. this of course depends on how big your character is:
    Code:
    track.hitTest(character._x, character._y,true){
    setProperty(character,_x,getProperty(character,_x)-5);
    }
    the mathematical:You get your characters _x and uses this _x to find the _y of the track underneith him. then see if their _y's the same and move him up if they are. To find which part of the track is at that _x, you can make them all 5 pixels wide and call them trackx1, trackx2 trackx3... Then you get the _x of your character and divide it by 5 and put it in a varable (eg current_X):
    Code:
    char_x=getProperty(character,_x);
    char_y=getProperty(character,_y);
    current_x=char_x/5;
    track_y=getProperty("trackx" + current_x,_y);
    if(track_y - char_y<-2){
    setProperty(character,_x,getProperty(character,_x)-5);
    }
    hope this made sense...

  18. #98
    Junior Member
    Join Date
    Apr 2001
    Posts
    5
    thank you very much
    =^i~= --x

  19. #99
    Member
    Join Date
    Feb 2003
    Location
    Canada
    Posts
    61
    I need some hittest help. I have a game that needs to have accurate collisions. The only two I know of are if(this.hittest(object1)){Blah Blah Blah} which has the bounding box limitation and if(this.hittest(object1._x, object1._y, true){Blah Blah Blah} which did not seem to accurately pick up what was transparent and what was not. (Don't ask why?)

    If you want to see what I mean (uses: if(this.hittest(object1._x, object1._y, true){})

    Just so you know, the shields that appear when they collide should come up at aprox the same time (they are colliding, right!) and its obvious they don't unless they hit each other dead center.

    SWF FILE
    FLA FILE (Flash MX)
    FLA FILE (Flash 5)

    Controls for Sovereign (Grey Ship)
    Left=Left Arrow
    Right=Right Arrow
    Forward=Up Arrow
    Reverse=Down Arrow
    Laser=Delete
    Torpedo=End
    Warp=Page Down

    Controls for Valdore (Green Ship)
    Left=A
    Right=D
    Forward=W
    Reverse=S
    Laser=Q
    Torpedo=E
    Warp=Z
    Cloak=C

  20. #100
    Ihoss
    Guest
    whats the problem? it seems to work fine for me...

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