A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: Help with movement for a game please

  1. #1
    Senior Member
    Join Date
    Jun 2001
    Posts
    169
    i know how to move a movie clip left, right, up, and down when keys are pressed on the keyboard. but i have this guy, and he's standing when nothing is being pressed. i have a seperate "running" animation to use when you press left or right. my question is how to do this, since all i know how to do is make the standing movie clip move without the running anmiation...do they both have to be together in the same movie clip? am i even making any sense?

  2. #2
    Senior Member
    Join Date
    Jun 2001
    Posts
    206
    I have been working on this too, trying to optimize everything now, as soon as it's finished, I'll post the code here. So far I have a character that has a standing animation, walking, punching, kicking, ducking and jumping.

    Here's how I did it:
    Every single animation (e.g. the punching animation) is in a seperate movie clip. I used the "standing" animation as some sort of a template for every move and worked from there to make the moves more fluid.

    So now I have about six seperate movie clips with all the moves, I put them into one "Master" movie clip (see the picture), that goes onto the stage.



    Note that I mirrored each movie clip for the facing left/right animation.
    I also "stretched" each movie clip over 7 frames, but that's just to be able to read the frame labels and keep some overview

    I put almost all the code on the "master clip" on stage.
    So, when I want my character to walk, I use this code:

    Code:
    onClipEvent (enterFrame) {
        if (Key.isDown(Key.LEFT) && attack_ready == true && duck_ready == true && jump_ready == true) {
            walk_ready = false;
            this._x -= 8;
            this.GotoAndStop("walkleft");
        } else if (Key.isDown(Key.LEFT) && attack_ready == true && duck_ready == true && jump_ready == false) {
            this._x -= 8;
            this.GotoAndStop("jumpleft");
        }
    }
    "walkleft" and "jumpleft" refer to frame labels with the same name in the master clip.
    The attack_ready, duck_ready etc. variables check if an action is being performed (e.g. punching) and if so, the walking animation doesn't start.

    If no keys are pressed, I want my character to do his "standing" animation, so I added this:

    Code:
    onClipEvent (keyUp) {
    	if (duck_ready == false && walk_left == true) {
    		this.duckleft.GotoAndPlay(3);
    	}
    	if (duck_ready == false && walk_left == false) {
    		this.duckright.GotoAndPlay(3);
    	}
    	if (walk_ready == false && walk_left == true) {
    		this.GotoAndStop("stanceleft");
    		walk_left = true;
    	}
    	if (walk_ready == false && walk_left == false) {
    		this.GotoAndStop("stanceright");
    		walk_left = false;
    	}
    There's some extra code there to check whether the character is ducking and in which direction it's facing, but basically this should give you an idea of how to do it.

    Good luck!

    V.



  3. #3
    Senior Member
    Join Date
    Jun 2001
    Posts
    169
    wow, thanks..but there has gotta be an easier way..im not gonna try that unless there isnt..hehe..thanks again

    actually, i think that is the best way to do it..mines not working however
    [Edited by whoa002 on 06-25-2001 at 10:19 PM]

  4. #4
    Senior Member
    Join Date
    Jun 2001
    Posts
    206
    If you just want your character to be able to display the running and standing animations, put those animations in the master movie clip and only add the code you need:

    Code:
    onClipEvent (enterFrame) {
        if (Key.isDown(Key.LEFT) 
            this._x -= 8;
            this.GotoAndStop("walkleft");
        }
        if (Key.isDown(Key.RIGHT) 
            this._x += 8;
            this.GotoAndStop("walkright");
        }
    }
    
    onClipEvent (keyUp) {
    		this.GotoAndStop("standing");	
    }
    The other code in my script is basically to check all sort of things (for example, I don't want the user to be able to go into the punching animation while jumping etc.), but you don't necessarily need it if you want to make a basic walking character. If so, the code above should be good enough to do the trick.


  5. #5
    Senior Member
    Join Date
    Jun 2001
    Posts
    169
    hey, do you have AIM or icq or something?

  6. #6
    Senior Member
    Join Date
    Feb 2001
    Posts
    314
    Here's a tip (I should have thought to share this earlier, Volando).

    You don't need to have animations for both right and left. If you use:

    this._xscale = -100

    You'll get the mirror image of your character, so a right walking animation becomes a left walking animation.

    Then when you want the character to face back the original direction, use:

    this._xscale = 100

  7. #7
    Senior Member
    Join Date
    Jun 2001
    Posts
    206
    You know Froth, I've been thinking about the possibility of that, but I never tried it. Luckily the mirroring of existing MC's doesn't really add to the file size (or so I thought, going to check that first!)

    Thnx for the tip!

  8. #8
    Senior Member
    Join Date
    Jun 2001
    Posts
    169
    hey volando, i cant seem to get mine to work, and i cant see what im doing wrong..the guy just moves left and right in his "standing" animation

  9. #9
    Senior Member
    Join Date
    Jun 2001
    Posts
    206
    Whoa2, I have to see the code to be able to tell you what's wrong. You can send me the .FLA and I'll see what I can do for you (treminator2@hotmail.com)

  10. #10
    Senior Member
    Join Date
    Jun 2001
    Posts
    169
    i sent you the .fla ...can anyone else try to help me too please? i can send whoever the .fla also

  11. #11
    Senior Member
    Join Date
    Jun 2001
    Posts
    206
    I received the .FLA and will look into it now.
    I'll let you know if I find anything "suspicious".

    Volando

  12. #12
    Senior Member
    Join Date
    Jun 2001
    Posts
    206
    I returned the updated .FLA and I will try and explain here what went wrong
    This was your code:
    Code:
    onClipEvent (enterFrame) {
    	if (Key.isDown(Key.RIGHT)) {
    		_x += 15;
    		gotoAndStop ("running");
    	} else {
    		gotoAndStop ("standing");
    	}
    }
    You simply forgot to add "this" to your syntax.
    Flash tries to find the "standing" label, but can't find it, because it's inside the Movie Clip, so all you've got to do is add it.
    This is what I made of it:

    Code:
    onClipEvent (enterFrame) {
    	if (Key.isDown(Key.RIGHT)) {
    		this._xscale = 100 
    		this._x += 15;
    		this.gotoAndStop ("running");
    		}
    	if (Key.isDown(Key.LEFT)) {
    		this._xscale = -100 
    		this._x -= 15;
    		this.gotoAndStop ("running");
    		}
    	if (Key.isDown("70")) {
    		this.gotoAndStop ("shooting");
    		}
    }
    onClipEvent (keyUp) {
          this.GotoAndStop("standing");
    }
    The this._xscale = +/-100 part flips the character horizontally (a nice tip donated by Froth, thank you kindly for that )

    Keycode 70 refers to the "S" key on your keyboard, so press S to shoot.

    The onClipEvent (keyUp) part works better for me than the else If etc. part, even though that method works as well.

    I also cleaned up some of your layers and added some stop actions to the master clip.

    Hope it is clear to you know and it would be nice if you showed the final game here, the characters look promising!

    Good luck!

    Volando.

  13. #13
    Senior Member
    Join Date
    Jun 2001
    Posts
    169
    THANK YOU THANK YOU! so thats what the problem was, youve solved many problems now, thanks man.

  14. #14
    Senior Member
    Join Date
    Jun 2001
    Posts
    206
    No problem, hope the development will go well from here!

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