A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: restricting movement from arrow keypad

Threaded View

  1. #1

    restricting movement from arrow keypad

    Hi,

    I am playing around making a little game from a tutorial and i am having trouble trying to limit where the "car" can travel on the screen. At present it has a free range and will disappear out of view if asked to. Can anyone make a suggestion what code i need to add? I have been searching and trying for two hours but just cant get it to work.

    This is what i have at present

    code:

    listener = new Object();
    listener.onKeyDown = function () {
    delete car.onEnterFrame;
    var yval = 0;
    var xval = 0;
    switch (Key.getCode()) {
    case Key.DOWN: yval = 8; car.rotate(30,30); break;
    case Key.UP: yval = -8; car.rotate(-30,30); break;
    case Key.LEFT: xval = -8; car.rotate(-30,30);break;
    case Key.RIGHT: xval = 8; car.rotate(30,30);
    }
    car.onEnterFrame = function(){
    this._y += yval;
    this._x += xval;

    }
    };



    Basically i just want to limit the cars movement to within the track!
    Any help or advice would be greatly welcomed.

    Barry

    EDIT: Added as tags. - jbum
    Last edited by jbum; 10-11-2004 at 03:44 PM.

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