A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: [F8] game help

  1. #1
    Member
    Join Date
    May 2008
    Posts
    33

    [F8] game help

    i wanted to know how i can create an object or character like in club penguin, where you click somewhere and it will walk over there. i have several movie clips for the character walking up,down,left,right,and diagonal in each direction.

    and i want to make it so when i move my mouse around the character will turn according to where the mouse is.

  2. #2
    Junior Member
    Join Date
    Nov 2007
    Posts
    15
    I've no idea what this "penguin club" you speak of is, but I recently wrote a script similar to what you appear to be looking for.

    PHP Code:
    //mousex/y will track the mouse coordinates
    mousex 0;
    mousey 0;
    //walkinterval will be the variable used in the later SetInterval command
    var walkinterval;
    //and this sets 'walkcheck' to listen for a mouse click
    walkcheck = new Object();
    Mouse.addListener(walkcheck);
    walkcheck.onMouseDown walkto;
    /*And now for the actual walking bit. This 'walkto' function will set 
    moousex/y to the mouse coordinates upon a mouse click and then have 
    myMovieClip move to that location.*/
    function walkto() {
            
    clearInterval(walkinterval);
            
    mousex _xmouse
            mousey 
    _ymouse
    //this would be where you would change myMovieClip to a "walking" movieclip
            
    walkinterval setInterval(function () {
                if (
    myMovieClip._x<=mousex) {
                    
    myMovieClip._x++;
                } else if (
    myMovieClip._x>=mousex) {
                    
    myMovieClip._x--;
                }
                if (
    myMovieClip._y<=mousey) {
                    
    myMovieClip._y++;
                } else if (
    myMovieClip._y>=mousey) {
                    
    myMovieClip._y--;
                }
                if ((
    myMovieClip._x<=(mousex+2) && myMovieClip._x>=(mousex-2)) && (myMovieClip._y<=(mousey+2) && myMovieClip._y>=(mousey-2))) {
                    
    clearInterval(walkinterval);
                    
    updateAfterEvent();
    //this would be where you could reload myMovieClip
                    
                
    }
            }, 
    10);
        } 
    It's also kind of boring to have a static image float across the screen, so you could use the attachMovie or loadMovie commands to change myMovieClip to a walking graphic and then reload myMovieClip at the end of the function where I've stated they should go.

    And sorry if the script's a bit messy I tried cleaning it up a bit when I put it on. It's simple enough though.

  3. #3
    Senior Member Ray Beez's Avatar
    Join Date
    Jun 2000
    Posts
    2,793
    Quote Originally Posted by Blueboy250
    I've no idea what this "penguin club" you speak of is, but
    Turbo charged version of Lance Priebe's "Penguin Chat". Purchased by Disney last year for $850 million US.

    Lance used to frequent this forum back in the day.

  4. #4
    Senior Member
    Join Date
    Mar 2008
    Posts
    301
    I thought we weren't supposed to talk about how much money we can expect to make from our games

  5. #5
    Member
    Join Date
    May 2008
    Posts
    33
    the only part of the script that i dont understand is where you put the names of the movie clips. im not sure where to put each walking clip. i have clips for the character walking up,down,left,right,diagonal in each direction and pictures of character standing those positions. can you specify where i put each one.

  6. #6
    Junior Member
    Join Date
    Nov 2007
    Posts
    15
    Ah alright. Well I'm assuming you're going to use 8 different directions then right? (ex. upright, up, upleft, right, left, downright, down, downleft)

    Well you're going to need to expand on my script a bit in order to do that. Mine basically handles one kind of 'standing' movieclip and one 'walking' movieclip. In order to do what you want to do with it you'll need to insert 'if' commands to check what direction myMovieClip will be moving in. But this should be a pretty easy change.

    So my script pretty much checks two directions for both the x and y values of myMovieClip. It checks whether myMovieClip should go up or down and left or right in this part of the script:

    PHP Code:
    walkinterval setInterval(function () { 
                if (
    myMovieClip._x<=mousex) { 
                    
    myMovieClip._x++; 
                } else if (
    myMovieClip._x>=mousex) { 
                    
    myMovieClip._x--; 
                } 
                if (
    myMovieClip._y<=mousey) { 
                    
    myMovieClip._y++; 
                } else if (
    myMovieClip._y>=mousey) { 
                    
    myMovieClip._y--; 
                } 
    Now what you'll need to do is change those 'if' commands to be more specific. For example, for the upright movement you would need an if command like

    PHP Code:
    if (myMovieClip._x<=mousex && myMovieClip._y>=mousey) { 
                    
    myMovieClip._x++;
                    
    myMovieClip._y--;
                    
    myMovieClip.loadMovie("walkingupright.swf");
                    if ((
    myMovieClip._x<=(mousex+2) && myMovieClip._x>=(mousex-2)) && (myMovieClip._y<=(mousey+2) && myMovieClip._y>=(mousey-2))) { 
                    
    clearInterval(walkinterval); 
                    
    updateAfterEvent();
                    
    myMovieClip.loadMovie("standingupright.swf")
    // you can also use an attackMovie command here, depending on how you're loading movieclips,

    And do a similar else if statement for each direction. Remember that the x and y values are relative to the top left hand corner of the stage. Sound good?
    Last edited by Blueboy250; 08-07-2008 at 10:13 PM.

  7. #7
    Member
    Join Date
    May 2008
    Posts
    33
    there were some errors in the script

  8. #8
    Senior Member hatu's Avatar
    Join Date
    Jan 2007
    Posts
    480
    Quote Originally Posted by WesIsGood
    I thought we weren't supposed to talk about how much money we can expect to make from our games
    That's quite an expectation
    http://hatu.biz
    Portfolio & games

  9. #9
    Junior Member
    Join Date
    Nov 2007
    Posts
    15
    Errors in the script? The part I just made up in that last post? Well I don't deny that - I was pretty tired when I came up with it. But it was really just the general idea for it, you're going to have to tinker with it a bit to get it working the way you want. And with the 'setInterval' command and a lot of 'if' statements I often lose track of the number of { brackets I've put in, make sure to check those as you work through it.

    I just switched the old 'if' statements for my new one and I didn't get any Formatting errors... do you mean the script isn't working correctly? Ah I think I know what it might be. Bear with me for a moment;

    In the new 'if' statements I have this:
    PHP Code:
    if (myMovieClip._x<=mousex && myMovieClip._y>=mousey) { 
                    
    myMovieClip._x++; 
                    
    myMovieClip._y--; 
                    
    myMovieClip.loadMovie("walkingupright.swf"); 
    With this script, as long as it keeps moving upright, it will keep loading the "walkingupright.swf" over and over again which will look like white space. Like I said I was tired, I didn't really think about that happening. I suppose the only way to get around it would be to have two different scripts running on it. Or, we could use one more 'if' statement.

    Um, alright. At the beginning of the whole script where I've put mousex = 0; and mousey = 0; add another variable called walkdirection = 0;. Then change this part of the script:

    PHP Code:
    myMovieClip.loadMovie("walkingupright.swf"); 
    to this:

    PHP Code:
    if(walkdirection !=  3){
    myMovieClip.loadMovie("walkingupright.swf"); 
    walkdirection 3;

    What I'm doing here is assigning the walkdirection variable a number based on what direction myMovieClip will be moving. An easy way to keep track of the eight directions would be to look at it like a telephone number pad. 1 would be upleft, 2 would be up, 3 would be upright etc. etc. And then in each 'if' statement that loads a different walking direction, have it assign walkdirection the proper number for the direction so it will only load the movie once as long as it keeps going in the same direction. I believe it should work alright.

    If you don't like the number-direction system you could use words, but I always find that makes variables more difficult. Still, the basic idea should work out for you.
    Last edited by Blueboy250; 08-08-2008 at 10:40 AM.

  10. #10
    Member
    Join Date
    May 2008
    Posts
    33
    that wasn't the problem. it said there were some errors with right paranthesis and right brace.

  11. #11
    Junior Member
    Join Date
    Nov 2007
    Posts
    15
    Mm, well that was still a damned good fix for a problem - whether it existed or not.

    But did you check that all the brackets and parentheses match up like I mentioned in the previous post? You haven't specified what part of the script is having issues so I don't know where to check.

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