A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Hit Test Help

  1. #1
    Member
    Join Date
    Oct 2004
    Posts
    32

    Hit Test Help

    Can anyone help me with the actionscript for some hit test/collision testing (i think thats what its called!), I have a layout which is a map and it has various paths which my character can move along (contolled by the mouse), id like to place some transperant objects or movie clips around the path which has collision detections so that my character cant go off the path.

    Ive started with applying this to my movieclip but no luck so far - Im not sure if its even the correct thing:

    onClipEvent (enterFrame) {
    if (this.hitTest(_root.char)) {
    _root.***NOT SURE WHAT TO PUT HERE***;
    }
    }
    Last edited by beautiFY; 10-16-2005 at 11:24 PM.

  2. #2
    The Flashman earl223's Avatar
    Join Date
    Sep 2000
    Location
    Marikina City, Philippines
    Posts
    876
    It depends actaully on what you want to happen. What is your script to move the character?
    i eat actionscripts for breakfast

  3. #3
    Member
    Join Date
    Oct 2004
    Posts
    32
    onClipEvent (load) {
    bounce = new Sound(this);
    dynaSounds = new Sound();
    leftBoundary = 150;
    rightBoundary = 400;
    topBoundary = 220;
    bottomBoundary = 300;
    boundaryHeight = bottomBoundary-topBoundary;
    boundaryWidth = rightBoundary-leftBoundary;
    quadrantSize = boundaryWidth/2;
    centerPoint = rightBoundary-quadrantSize;
    }
    onClipEvent (mouseMove) {
    if (_root._xmouse>leftBoundary && _root._ymouse>topBoundary && _root._xmouse<rightBoundary && _root._ymouse<bottomBoundary) {
    startDrag(this, true);
    topToBottomPercent = ((((_root._ymouse-topBoundary)/boundaryHeight)*100)/2)+50;
    bounce.setVolume(topToBottomPercent);
    this._xscale = topToBottomPercent;
    this._yscale = topToBottomPercent;
    panAmount = ((_root._xmouse-centerPoint)/quadrantSize)*100;
    bounce.setPan(panAmount);
    } else {
    stopDrag();
    }
    }
    onClipEvent (mouseDown) {
    randomSound = random(3);
    randomLoop = random(2) + 1;
    dynaSounds.attachSound("Sound"+randomSound);
    dynaSounds.start(0, randomLoop);
    }
    onClipEvent (keyDown) {
    dynaSounds.stop();
    }
    haha its from a basketball game, but i am adapting it to my game, i will take out the irrelevant bits when i get a chance. Basically you move the mouse and the character moves too, but it gets smaller with perspective. id of liked to change this to keys but thats another story :P im just hoping there is something simple that i could apply to the shapes so that it wont let the mouse and character go past this shape.....

  4. #4
    The Flashman earl223's Avatar
    Join Date
    Sep 2000
    Location
    Marikina City, Philippines
    Posts
    876
    ahh ok... since your using startDrag to move the character... all you gotta do is stop it:

    onClipEvent (enterFrame) {
    if (this.hitTest(_root.char)) {
    _root.char.stopDrag();
    }
    }
    Last edited by earl223; 10-17-2005 at 01:26 AM.
    i eat actionscripts for breakfast

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