A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Maze hitTest

  1. #1
    Member
    Join Date
    Feb 2002
    Location
    Chicago, Atlanta
    Posts
    57

    Maze hitTest

    Im making a maze that ball travels through. I am succesful on one wall. But when I come down to the other side it brings it up. How do make the side a hitTest? or can give me advice if theres better solutions. Thanks....
    I have attached it to the ball named circle. I have include the file


    //the hitTest
    if (hitTest(_level0.wall)==true) {
    _y = _y-10;
    this below is the full code
    onClipEvent (enterFrame) {
    if (Key.isDown(37)) {
    _x=_x-10;
    }
    if (Key.isDown(38)) {
    _y=_y-10;
    }
    if (Key.isDown(39)) {
    _x=_x+10;
    }
    if (Key.isDown(40)) {
    _y=_y+10;
    }
    //the hit test
    if (hitTest(_level0.wall)==true) {
    _y = _y-10;


    }

    }
    Attached Files Attached Files

  2. #2
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    I would do a coordinate based hit test which checks the direction you are trying to travel in.

    Your current makes an adjustment to the position, and then does an 'undo' on that adjustment if there is a hit.

    I would check to see if there is a hit on the target coordinates before making the actual adjustment, like so:

    code:

    onClipEvent (enterFrame) {

    var xd = 0; // direction of movement
    var yd = 0;
    if (Key.isDown(37)) {
    xd = -10;
    }
    if (Key.isDown(38)) {
    yd = -10;
    }
    if (Key.isDown(39)) {
    xd = 10;
    }
    if (Key.isDown(40)) {
    yd = 10;
    }
    // check if there is a collision with the target coords
    if (!_level0.wall.hitTest(_x+xd,_y+yd))
    {
    // if not, make the adjustment
    _x += xd;
    _y += yd;
    }
    }



    Also, there's another way to do it, the method I used in these mazes:

    http://krazydad.com/fungames.php

    In these mazes, I don't use hitTest at all, instead I keep track of where the valid paths exiting each cell are and only allow movement along the valid paths, tweening from the center of one cell to the next.

    So rather than using hitTest, I am checking a data structure to see if a bit is set that corresponds to the desired direction of movement.

    - Jim

  3. #3
    Member
    Join Date
    Feb 2002
    Location
    Chicago, Atlanta
    Posts
    57

    Thanks you

    Thanks so very much for the help.

  4. #4
    Junior Member
    Join Date
    Mar 2005
    Location
    minds playin tricks on me
    Posts
    18
    http://www.actionscript.org/tutorial...es/index.shtml

    I remembered seeing this, thought you might be interested.

    webg
    minds playin tricks on 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