How to move MC with setting a boundaries?
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: How to move MC with setting a boundaries?

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    3

    How to move MC with setting a boundaries?

    Hi,
    I have the following code that allow me to move MC with the keyboards.
    How i can set the boundaries not as a stage? what i'm trying to do is to move my character just a little.


    onClipEvent (enterFrame) {
    if (Key.isDown(Key.UP)) {
    if(this._y > 0){
    this._y -= 5;
    }
    }
    }

    onClipEvent (enterFrame) {
    if (Key.isDown(Key.DOWN)) {
    if(this._y < Stage.height){
    this._y += 7;
    }
    }
    }

    onClipEvent (enterFrame) {
    if (Key.isDown(Key.LEFT)) {
    if(this._x > 0){
    this._x -= 7;
    }
    }
    }

    onClipEvent (enterFrame) {
    if (Key.isDown(Key.RIGHT)) {
    if(this._x < Stage.width){
    this._x += 7;
    }
    }
    }


    Thanks a lot!

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,051
    Hi,

    Maybe something like so
    PHP Code:
    onClipEvent (load) {
        var 
    left:Number 10;
        var 
    right:Number 200;
        var 
    top:Number 10;
        var 
    bot:Number 200;
    }

    onClipEvent (enterFrame) {
        if (
    Key.isDown(Key.UP))
        {
            if (
    this._y top)
            {
                
    this._y -= 5;
            }
        }
        if (
    Key.isDown(Key.DOWN))
        {
            if (
    this._y bot)
            {
                
    this._y += 7;
            }
        }
        if (
    Key.isDown(Key.LEFT))
        {
            if (
    this._x left)
            {
                
    this._x -= 7;
            }
        }
        if (
    Key.isDown(Key.RIGHT))
        {
            if (
    this._x right)
            {
                
    this._x += 7;
            }
        }

    alter the numbers to suit your needs.

  3. #3
    Junior Member
    Join Date
    Jul 2013
    Posts
    3
    Yes it's great! thanks a lot!!!

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

Poll by Flashkit.com