A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: cant get this to work correctly, any help please?

  1. #1
    Member
    Join Date
    Oct 2008
    Posts
    37

    cant get this to work correctly, any help please?

    I cant get this moving background style hittest to work correctly, its kinda working but not correctly.

    I'll explain.. You can move the background using the left and right keys and move the floating dot with the up and down keys, i am wanting the background/dot to stop moving if a hittest occurs (which it does) but once it hittests then nothing will move at all..

    i've attached a fla if anyone can help, its being saved using flash 8.

    also here is the code and a screenshot incase you cannot open flash 8 fla's.



    code:

    var leftEdge:Number = 0;
    var rightEdge:Number = -510;
    var topEdge:Number = 20;
    var bottomEdge:Number = 380;
    var moveSpeed:Number = 5;

    _root.onEnterFrame = function() {
    if (Key.isDown(Key.RIGHT)) {
    if (_root.xmove._x > rightEdge){
    if (!_root.xmove.hitTest(_root.dot._x, _root.dot._y, true)) {
    _root.xmove._x -= moveSpeed;
    }
    }
    }
    if (Key.isDown(Key.LEFT)) {
    if (_root.xmove._x < leftEdge){
    if (!_root.xmove.hitTest(_root.dot._x, _root.dot._y, true)) {
    _root.xmove._x += moveSpeed;
    }
    }
    }
    if (Key.isDown(Key.UP)) {
    if (_root.dot._y > topEdge){
    if (!_root.xmove.hitTest(_root.dot._x, _root.dot._y, true)) {
    _root.dot._y -= moveSpeed;
    }
    }
    }
    if (Key.isDown(Key.DOWN)) {
    if (_root.dot._y < bottomEdge){
    if (!_root.xmove.hitTest(_root.dot._x, _root.dot._y, true)) {
    _root.dot._y += moveSpeed;
    }
    }
    }
    }



    Dot is the dot and xmove is the background.

    thanks in advance.
    Attached Files Attached Files
    Last edited by mexicanbean; 02-26-2010 at 03:20 PM.

  2. #2
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    Somewhat confused... you say
    i am wanting the background/dot to stop moving if a hittest occurs (which it does), but once it hittests then nothing will move at all.
    What are you trying to get it to do once the hitTest occurs?
    Wile E. Coyote - "Clear as mud?"

  3. #3
    Member
    Join Date
    Oct 2008
    Posts
    37
    i just want it to act like a wall, so you can move away from it but not through it.

  4. #4
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    stop();
    
    var leftEdge:Number = 0;
    var rightEdge:Number = -510;
    var topEdge:Number = 20;
    var bottomEdge:Number = 380;
    var moveSpeed:Number = 5;
    var moveSpeedX:Number = 0;
    var moveSpeedY:Number = 0;
    //
    function minMax(hi, mid, low) {
    	return Math.max(Math.min(hi, mid), low);
    }
    _root.onEnterFrame = function() {
    	xmove._x = minMax(leftEdge, xmove._x, rightEdge);
    	dot._y = minMax(bottomEdge, dot._y, topEdge);
    	if (xmove.hitTest(dot._x, dot._y, true)) {
    		xmove._x += 0-moveSpeedX;
    		dot._y += 0-moveSpeedY;
    	}
    	moveSpeedX = 0;
    	moveSpeedY = 0;
    	if (Key.isDown(Key.RIGHT)) {
    		moveSpeedX = 0-moveSpeed;
    	} else if (Key.isDown(Key.LEFT)) {
    		moveSpeedX = moveSpeed;
    	}
    	if (Key.isDown(Key.UP)) {
    		moveSpeedY = 0-moveSpeed;
    	} else if (Key.isDown(Key.DOWN)) {
    		moveSpeedY = moveSpeed;
    	}
    	xmove._x += moveSpeedX;
    	dot._y += moveSpeedY;
    };

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