A Flash Developer Resource Site

Page 8 of 11 FirstFirst ... 4567891011 LastLast
Results 141 to 160 of 215

Thread: The elusive hitTest explained

  1. #141
    Flashoholic OneMrBean's Avatar
    Join Date
    Feb 2002
    Posts
    168
    It seems to me that your code

    Code:
    if(_root.Symbol 16, hittest(_root.Symbol 4)){
        _root.score +=1;
    }
    only had one error, and that was that you did not capatalize the word Test in hitTest. I know, it really shouldn't make a difference, but it's a Flash function, and everything is case sensitive. I'm glad it worked out, though, and you're welcome.

    - Bean

  2. #142
    Junior Member
    Join Date
    Aug 2003
    Location
    your imagination
    Posts
    20
    ok, i'll remember that.
    i got another question, i'm making a basketball game and when the ball goes up it crosses the "sixteen" and adds a score to my scoreboard, how do i stop this?(ball="four")
    oh and what does a case sensitive have to do with a ')'
    <:::::[]***@marcus@**{}:::>

  3. #143
    Flashoholic OneMrBean's Avatar
    Join Date
    Feb 2002
    Posts
    168
    "when the ball goes up it crosses the "sixteen" and adds a score to my scoreboard, how do i stop this?(ball="four")"

    Isn't this the effect you wanted to create in the first place? Perhaps I'm not understanding your question correctly.

    I guess to stop it, delete the code that I wrote for you


    "oh and what does a case sensitive have to do with a ')'"

    It has nothing to do with it ^_^. Your parentheses, that being '(' and ')', were used perfectly. I said the problem was your capatalization of the word "Test" in "hitTest". I referred to it being "case sensitive", which means that there's a difference between "t" and "T". I hope this clears things up.

    - Bean

  4. #144
    Junior Member
    Join Date
    Aug 2003
    Location
    your imagination
    Posts
    20
    i mean i want the score to change when it goes through the basket(down) not when it is in the air(up)
    <:::::[]***@marcus@**{}:::>

  5. #145
    Flashoholic OneMrBean's Avatar
    Join Date
    Feb 2002
    Posts
    168
    Why not just make "sixteen" small enough so it's only on top of the basket, thus disallowing the ball to ever hit it while going upwards?

    If the ball happens to go at an angle where it will "make contact with" the basket while going up, then you might have a little work to do. You could make a variable that makes sure it first went upwards, like so.

    Code:
    if(_root.Symbol 16, hittest(_root.Symbol 4)){
        if(ballWentUp == 1){    
            _root.score += 1;
            ballWentUp = -1;
        }
        ballWentUp += 1;
    }
    Basically, this checks if the ball is hitting "sixteen". If so, then it checks if the ball went up, which is the variable ballWentUp. The first time it checks, it wont be true, so it passes the scoring part and adds 1 to ballWentUp, which means it's true. The next time the ball hits the basket, ballWentUp will be true, so it will go into that second if statement, which adds the score, and also makes ballWentUp equal to -1 because it will then be incremented to 0, which will put it back in place for the next time that you shoot.
    NOTE: This will only work if the ball ALWAYS hits "sixteen" while going upwards.

    Hope this works out for ya!

    - Bean

  6. #146
    Junior Member
    Join Date
    Aug 2003
    Location
    your imagination
    Posts
    20
    thx that worked perfectly
    <:::::[]***@marcus@**{}:::>

  7. #147
    Flashoholic OneMrBean's Avatar
    Join Date
    Feb 2002
    Posts
    168
    Glad to hear it finally worked out!

    For other matters on your game, it's suggested you post a new thread so your questions aren't hidden elsewhere, such as the end of this almost four-thousand post sticky thread. ^^

    You're welcome.

    - Bean

  8. #148
    Junior Member
    Join Date
    Sep 2003
    Location
    California
    Posts
    7

    okay i need a little help....

    this is what i have for my side scrolling platform game:

    onClipEvent (keyUp){
    _root.walk.gotoAndStop(1);
    }
    onClipEvent (enterFrame) {
    if (Key.isDown(Key.LEFT)&& this._x>50) {
    _root.walk.play();
    _root.walk._x -= 15;
    _root.walk._xscale=-100
    }
    }
    onClipEvent (enterFrame) {
    if (Key.isDown(Key.RIGHT)&& this._x<495) {
    _root.walk.play();
    _root.walk._x += 15;
    _root.walk._xscale = 100;
    }
    }onClipEvent (enterFrame) {
    if (Key.isDown(Key.SPACE) && !jumping) {
    _root.walk.gotoAndPlay(6)
    vel_y = 36;
    jumping = true;
    }
    if (jumping == true) {
    vel_y -= 2;
    if (vel_y<=-15) {
    vel_y = -15;
    }
    this._y -= vel_y;
    }
    if (_root.ground.hitTest(this._x+30, this._y+30, true)) {
    vel_y = 0;
    jumping = false;
    }
    }
    onClipEvent (enterFrame) {
    this._y += 12;
    if (_root.ground.hitTest(this._x, this._y+30, true)) {
    this._y -= 12;
    }
    }

    but i cant figure out how to get my character to go to the next scene when he exits off the right or left side of the screen, can anyone help? i would really appreciate it

  9. #149
    Moderator
    FK Junkie
    TiefighT's Avatar
    Join Date
    Aug 2000
    Posts
    683
    Optimizing collision detection discussion and examples

    That thread is from a while back, just forgot to put it in the stickies until now .

  10. #150
    Junior Member
    Join Date
    Oct 2003
    Location
    London
    Posts
    6

    ok folks, riddle me this

    hey, i'm a joinin this hitTest party,i got me a question that i can't seem to find the answer to anywhere else in this thread or elsewhere on the board. If you've read my other two posts pleading for help, you'll know that i'm putting together a zelda-style interface for my cv (i'm an animator by trade, just wanted to do something a little different ). I eventually got my lil guy walking properly, then i managed to make him stop at objects, however, he aint stopping at everything, he'll walk right on through somethings sometimes, and the big ol' gallery at the top, he walks through that every time. As far as my feeble brain can tell, this may be because the hitTest area is partly offscreen? would this make a difference, how can i solve it? sorry for the long message but i'm well stuck! here's the swf: gruffcv , and i'll upload the fla
    Attached Files Attached Files
    Psst, wanna see my monkey?

  11. #151
    Ihoss
    Guest
    god, theres too much to read for a tired mind, so ill ask and hope u havent answered already, and if u have, sorry. my problem is that i want to hittest 2 things which are in an mc. should that really be a problem, cuz i just cant get it to work. ive allready sked in the object thread, but since its now a hittest problem i ask here. if you know y it wont work, please tell me.

    *edit*
    I just read this and i see that i should explain it a bit better. its for my mario kart racing game (or ihoss-cart, obvioulsy), and i have a map in the corner wiht the car as an icon. when i move forward the car in the map moves forward. what i want to is to see if the car is on the road and if it isnt, slow it down. therefore i added a road shape to the map and hittest it from the car icon to see if they hit.
    code:

    if (_parent.shape.hitTest(this._x,this._y,true)) {
    _parent._parent.maxspeed=20;
    }else{
    _parent._parent.maxspeed=10;
    }


    it is relative cuz im going to load it inot another movie, and im sure all the mc exist.
    i would really apreaciate it if someome could help me.

  12. #152
    Junior Member
    Join Date
    Nov 2003
    Posts
    1
    Hi Ed //

    I really appreciate looking at your source files. They have been most helpful to me. I noticed a minor problem with {simple_shooter.fla} from your download page. The counter is not working after you kill an enemy. I took the second frame out in the enemy_mc because it had a stop action on that frame. That seemed to fix the problem. I know this is minor, I just thought I would bring it to your attention.

    Thanks again!

    :b

  13. #153
    Junior Member
    Join Date
    Dec 2003
    Posts
    1
    Now, "hyrossia" is the map mc. I have the map scrolling the way I want it now....but the problem now is the collision detection is out of whack (if the map is scrolling while you hit a wall you begin to go through it). Any solutions for this?
    In scrolling, the hitTest is pretty much like moving accept backwards
    so you would have to create a sperate scroll function like

    function move(x, y) {
    if(!_root.map.hitTest(_x+x+b.xmin, _y+y+b.ymin, true)) {
    _x += x;
    _y += y;
    }

    function scroll(x, y) {
    if(!_root.map.hitTest(_x-x-b.xmin, _y-y-b.ymin, true)) {
    _root.map._x += x;
    _root.map._y += y;
    }

  14. #154
    Junior Member
    Join Date
    Dec 2000
    Posts
    28

    game

    Hey,

    Ive used hittest to deplete the health of my player whenever he hits a baddie movieclip - The problem is - I want the baddie to die and the player to lose say 25 of their health all in one go.

    At the moment the player keeps losing life as long as he is in contact with the baddie movieclip......get me?

    The way I would like it is in the bombs away game ie: when the plane hits the surface to air missiles they explode and the plane loses some energy....

    Pete M

  15. #155
    Member
    Join Date
    Jul 2002
    Posts
    62
    Hello people, i'm wondering if someone can help me out.

    I've been using the following code to control a movieclip's movement with the keys. This being Ed Mack's code from the first page i think. However, what i'd really like to be able to do is to have the movieclip attached to the mouse and try and get the hit test to work that way. I've had a couple of attempts and have searched for relevant threads, but as yet i've had no luck on either count.

    If anyone has any ideas or knows how to do this, i'd be really grateful for their advice.

    Thanks again


    --- code starts ---

    onClipEvent(load){
    s = 5;
    b = this.getBounds(this);

    function move(x,y){
    if(!_root.hit.hitTest(_x+x+b.xmin+1,_y+y+b.ymin+1, true)){
    if(!_root.hit.hitTest(_x+x+b.xmax-1,_y+y+b.ymin+1,true)){
    if(!_root.hit.hitTest(_x+x+b.xmin+1,_y+y+b.ymax-1,true)){
    if(!_root.hit.hitTest(_x+x+b.xmax-1,_y+y+b.ymax-1,true)){
    _x += x;
    _y += y;
    }
    }
    }
    }
    }
    }

    onClipEvent(enterFrame){
    if(Key.isDown(Key.UP)){
    move(0,-s);
    }
    if(Key.isDown(Key.DOWN)){
    move(0,s);
    }
    if(Key.isDown(Key.LEFT)){
    move(-s,0);
    }
    if(Key.isDown(Key.RIGHT)){
    move(s,0);
    }
    }


    --- code ends ---

  16. #156
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Originally posted by triple j
    I've been using the following code to control a movieclip's movement with the keys. This being Ed Mack's code from the first page i think. However, what i'd really like to be able to do is to have the movieclip attached to the mouse and try and get the hit test to work that way. I've had a couple of attempts and have searched for relevant threads, but as yet i've had no luck on either count.
    Do you want movie clip to move to the direction of mouse coordinates? Only when mouse is clicked? Or do you want movie clip to appear in mouse position?

    Its not hard to change the code to do following:
    *when mouse is clicked check which way mouse is from mc current position
    *start moving in that direction
    *move until hit the wall or mouse position is reached

  17. #157
    Member
    Join Date
    Jul 2002
    Posts
    62
    Thanks for the reply Tony

    The movieclip will be in the mouse's position, so a start drag will be fine for that or code saying the the x and y values of the movieclip equal the x and y values of the mouse, whichever would be easiest to implement into the hittest.

    I tried re-working the code and included a start drag with the movieclip locked to the mouse center, but i wasn't sure how to include the move function into it. As soon as i included the start drag the hittest stopped working. The answer is probably staring me in the face, but i can't seem to find the solution just yet.

    Any help you can offer would be great

  18. #158
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    I dont think you can use drag in this case. Try this:
    code:

    onClipEvent (enterFrame) {
    if (_root._ymouse<this._y) {
    move(0, -s);
    }
    if (_root._ymouse>this._y) {
    move(0, s);
    }
    if (_root._xmouse<this._x) {
    move(-s, 0);
    }
    if (_root._xmouse>this._x) {
    move(s, 0);
    }
    }


  19. #159
    Member
    Join Date
    Jul 2002
    Posts
    62
    That's excellent Tony, thank you very much for your help

    It's a shame you can't use drag for this as it would have been alot smoother. Would it be possible to use the constrain to rectangle option in the start drag to limit its movement on the hittest ? For example, if the right hand side of the movie clip was hitting something, i would only have start drag for up, down and left ?? I'm not sure if it could work like that.

    Once again thank you so much for your time and knowledge, it's been a big help

  20. #160
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Originally posted by triple j
    Would it be possible to use the constrain to rectangle option in the start drag to limit its movement on the hittest ? For example, if the right hand side of the movie clip was hitting something, i would only have start drag for up, down and left ?? I'm not sure if it could work like that.
    I never tried anything like that. First, I think you can only change constrain to rectangle option when you start the drag, that would mean you have to constantly stop dragging and start again.

    And you cant actually hittest dragged movie clip against where it would go.

    If you want, you could still use the _xmouse/_ymouse like this:
    code:

    onClipEvent (load) {
    b = this.getBounds(this);
    function move (x, y) {
    if (!_root.hit.hitTest(_root._xmouse+b.xmin+1, _root._ymouse+b.ymin+1, true)) {
    if (!_root.hit.hitTest(_root._xmouse+b.xmax-1, _root._ymouse+b.ymin+1, true)) {
    if (!_root.hit.hitTest(_root._xmouse+b.xmin+1, _root._ymouse+b.ymax-1, true)) {
    if (!_root.hit.hitTest(_root._xmouse+b.xmax-1, _root._ymouse+b.ymax-1, true)) {
    _x = _root._xmouse;
    _y = _root._ymouse;
    }
    }
    }
    }
    }
    }
    onClipEvent (mouseMove) {
    move();
    }


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