dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: need help using hit test

  1. #1
    Junior Member
    Join Date
    May 2004
    Location
    Springfield, OR
    Posts
    21

    need help using hit test

    here's teh deal. (im using action script 1).

    ive got a wall called blocks20 with this script:

    Code:
    onClipEvent (enterFrame) {
        _y = _y -20;
    }
    so that makes that wall move up (why up instead of down, i don't know. maybe its because ive got it inside of another movie clip).

    and ive got this ball above it that falls. when it hits the wall, i want it to rise up as if the wall is pushing it up.
    here's teh script that im using that don't work:

    Code:
    onClipEvent (enterFrame) {
        _y = _y +10;
        if (_root.ball.hitTest(blocks20, true)) {
            _y = _y -20;
        }
    }
    now it does fall down, but it goes right down past teh wall. as you can see, it must be flawed. i have no clue how to use hitTest right, and maybe there's some other problem too. can you tell me what i should use for that last part?

  2. #2
    doItLikeThis
    Join Date
    Jan 2004
    Location
    :noitacoL
    Posts
    1,080
    first off you have'nt provided the instance of the ball, who's _y property will change so it should be like:-
    code:

    onClipEvent (enterFrame) {
    _y = _y +10;
    if (_root.ball.hitTest(blocks20, true)) {
    _root.ball._y = _root.ball._y -20;
    }
    }


    but I'd suggest
    code:

    onClipEvent (enterFrame) {
    _y = _y +10;
    while (_root.ball.hitTest(blocks20, true)) {
    _y -= 1;
    }
    }

    -Aditya

  3. #3
    Pedro
    Join Date
    Nov 2003
    Location
    UK
    Posts
    69
    Oh and subracting from the _y walue makes it go up because _y and _x are counted from the registration point (Usually the top-left corner). They increase as you get further away from the reg point so going down makes _y increase. Therefore, subtracting from _y makes things go upwards.

    Hope this helps.
    "I feel like a king!"

  4. #4
    Junior Member
    Join Date
    May 2004
    Location
    Springfield, OR
    Posts
    21
    Originally posted by adit_ya_sharma
    first off you have'nt provided the instance of the ball, who's _y property will change so it should be like:-
    code:

    onClipEvent (enterFrame) {
    _y = _y +10;
    if (_root.ball.hitTest(blocks20, true)) {
    _root.ball._y = _root.ball._y -20;
    }
    }


    but I'd suggest
    code:

    onClipEvent (enterFrame) {
    _y = _y +10;
    while (_root.ball.hitTest(blocks20, true)) {
    _y -= 1;
    }
    }

    well i can't say that either of those scripts worked. here are some things that i think you should know: the ball and wall are not in the same layer on the timelene. and, i said that blocks20 had the action script on it. it doesnt. it's a movie clip inside of it that does.

  5. #5
    Junior Member
    Join Date
    May 2004
    Location
    Springfield, OR
    Posts
    21
    here i will give you the FLA. it is how i tried to set it up. please make all the action script changes so that when the ball hits the wall, it stops falling and rides up with the wall.

    what i did was save a copy, and then remove all the stuff that makes the filesize huge (music, stuff i didnt use yet, backgrounds, etc)
    Attached Files Attached Files

  6. #6
    doItLikeThis
    Join Date
    Jan 2004
    Location
    :noitacoL
    Posts
    1,080
    Hey. The code was very uneven, see inside the blocks 20 mc for the new code, I hope this is what you want.
    -Aditya

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