A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Limited movement (till certain position only)

  1. #1
    Junior Member
    Join Date
    May 2019
    Posts
    26

    Limited movement (till certain position only)

    Hi, I use standard code for Movie_Clip movement:

    onClipEvent (enterFrame) {
    if(Key.isDown(Key.RIGHT)) {
    _x += 10;
    }
    }

    But in that case, MC can move unlimited and continue to move out of the screenview. Is there some code for limited move, till certain position only? For example, when MC arrives to position _x=200, it can not move any more in that direction, it just can come back. So, it could move in _x(+) direction only when _x<200.

  2. #2
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    927
    _x = Math.min (200, _x + 10);
    who is this? a word of friendly advice: FFS stop using AS2

  3. #3
    Junior Member
    Join Date
    May 2019
    Posts
    26
    It works nice. Thanks.

    onClipEvent (enterFrame) {
    if(Key.isDown(Key.RIGHT)) {
    _x = Math.min (200, _x + 10);
    }
    }

  4. #4
    Junior Member
    Join Date
    May 2019
    Posts
    26
    For limited movement, between point 20 and point 200, code is:

    onClipEvent (enterFrame) {
    if(Key.isDown(Key.RIGHT)) {
    _x = Math.min (200, _x + 10);
    }
    if(Key.isDown(Key.LEFT)) {
    _x = Math.max (20, _x - 10);
    }
    }

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