A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Character Movement NEED HELP!

  1. #1
    Member
    Join Date
    Oct 2008
    Posts
    41

    Character Movement NEED HELP!

    Okay, so I have an MC for my char, inside there are 4 frames, one with him facing left(idle), one facing right(idle), one facing left(running MC), and on facing right(running MC).

    I have the stop action on all of the frames and on the running movieclips i have these two actions.

    Code:
    onClipEvent (enterFrame) {
    	if (!Key.isDown(Key.RIGHT)) {
    		_root.player.gotoAndStop(1);
    	}
    }
    or...

    Code:
    onClipEvent (enterFrame) {
    	if (!Key.isDown(Key.LEFT)) {
    		_root.player.gotoAndStop(2);
    	}
    }
    on the MC in the main scene, i have this action.


    Code:
    onClipEvent (load) {
    	speed = 15;
    }
    onClipEvent (enterFrame) {
    	if (Key.isDown(Key.UP)) {
    		this._y -= speed;
    		this.gotoAndStop(3);
    	}
    	if (Key.isDown(Key.DOWN)) {
    		this._y += speed;
    		this.gotoAndStop(4);
    	}
    	if (Key.isDown(Key.RIGHT)) {
    		this._x += speed;
    		this.gotoAndStop(3);
    	}
    	if (Key.isDown(Key.LEFT)) {
    		this._x -= speed;
    		this.gotoAndStop(4);
    	}
    }
    The problem I have though is that when I press up or down, it goes to the right frame, but the movieclip doesn't play, it plays when i use right or left though... Also, how can I make it so it also plays the animation when you press 2 keys at a time eg. right+left.

  2. #2
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Maybe you need to check for both keys in running mc:

    if (!Key.isDown(Key.RIGHT) && !Key.isDown(Key.UP)) {

  3. #3
    Member
    Join Date
    Oct 2008
    Posts
    41
    that didn't change anything but for some reason now the right+up, right+down and the down ones work...

  4. #4
    Senior Member
    Join Date
    Mar 2008
    Posts
    301
    Try replacing things like this ...

    Code:
    if (Key.isDown(Key.UP)) {
    this._y -= speed;
    this.gotoAndStop(3);
    }
    ... with things like this ...

    Code:
    if (Key.isDown(Key.UP)&&(this.currentFrame != 3)) {
    this._y -= speed;
    this.gotoAndStop(3);
    }
    ... and see if that fixes anything

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