A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Problem with movement

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    14

    Problem with movement

    I have a Problem with this animation, i want to do when you press "1" detect the position of character and attack for left or right, but i can do that, for me only work when press A or D + 1.

    Example : http://www.gamematch.es/flash/luffy2.swf
    Use A and D for Move and 1 For try to attack

    The code is that

    Actionscript Code:
    onClipEvent(load) {
    lufpos=0; //Character position
    golpe = false; //Check its character its in combat
    }
    onClipEvent (enterFrame) { // if character hit with the other npc come back
        if (this.hitTest(_root.coco)) {
            this._x = _x - 21;
        }
    }
    onClipEvent(keyUp) { // Stand mode Animation for detect left or right
    if (Key.getCode() == 65 || Key.getCode() == 68) { // si suelta A o D, detiene la animación
    if (lufpos == 1) { // Si está mirando a la derecha
        gotoAndPlay(1);// XX = Frame del muñeco parado mirando a la derecha
         lufpos=0;
            } else { // lufpos == 2
                gotoAndPlay(12); // YY = Frame del muñeco parado mirando a la derecha
                lufpos=0;
            }
          }

        }
    onClipEvent(keyDown) { // Detect character uses 1 for attack
    if (Key.getCode() == 49) {
    if (lufpos == 1){ //Animation for right
        if (golpe == false){
        gotoAndPlay(38);
        golpe = true;
    }
    }
    if (lufpos == 2){ //Animation for left
        if (golpe == false){
        gotoAndPlay(47);
        golpe = true;
    }
    }
    }
    if (Key.getCode() == 65) { //Run mode Left animation
        if (lufpos <=1) {  
        gotoAndPlay(24);
        lufpos = 2;
        _x = _x - 7;
    } else {
        _x = _x - 7;
    }
    }
    if (Key.getCode() == 68){ //Run mode Right animation
        if (lufpos == 0){
            gotoAndPlay(62);
            lufpos = 1;
         _x = _x + 7;
            }
        if (lufpos == 2) {
         gotoAndPlay(62);
         lufpos = 1;
         _x = _x + 7;
        } else {
        _x = _x + 7;
    }
    }
    }


    PD: Sorry so much for my bad english.

    Thanks for your help

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Hello, and welcome to FlashKit forums

    First of all, I wanna say, LUFFY FOR THE WIN

    Now, for the code. I don't really like that way of yours, so I'm gonna rewrite the whole code to something easier, okay?

    For this code, you only need to make animation Right-side, the Actionscript will flip/turn the movieclip the other way, when running left or even attacking left. Just make sure that every animation inside the character movieclip, is inside another movieclip. For example, if gotoAndStop(2); - on Frame 2 inside Luffy Movieclip, there will be another movieclip with the Run Right animation:

    Actionscript Code:
    onClipEvent(load) {
        lufpos = 0;
        golpe = false;
        mover = true;
        speed = 7;
        xscale = this._xscale;
    }

    onClipEvent (enterFrame) {
        if (this.hitTest(_root.coco)) {
            this._x -= 21; // change this to 7 and see what happens
        }
        if(Key.isDown(Key.RIGHT)){
            if(golpe == false && mover == true){
                this._x += speed;
                this._xscale = xscale;
                golpe = true;
                gotoAndStop(2); // run animation for RIGHT
            }
        } else {
            golpe = false;
        }
        if(Key.isDown(Key.LEFT)){
            if(golpe == false && mover == true){
                this._x -= speed;
                this._xscale = xscale*-1; // change movieclip to LEFT
                golpe = true;
                gotoAndStop(2); // run animation for LEFT
            }
        } else {
            golpe = false;
        }
        if(Key.isDown(49)){
            if(golpe == false){
                gotoAndStop(3); // attacking animation
                mover = false;
            }
        } else {
            mover = true;
        }
        if(!Key.isDown(Key.RIGHT) && !Key.isDown(Key.LEFT) && !Key.isDown(49)){ // if none of those keys are being pressed
            gotoAndStop(1); // idle animation (doing nothing, standing)
        }
    }

    This is another way of doing what you did, but in my opinion, it's better and more effective. I hope this helps - and LUFFY IS AWESOME ^^

    PS: Make sure to make a movieclip inside the Luffy movieclip, for each action - a movieclip on Frame 1, for standing still, movieclip on Frame 2, for running Right, and movieclip on Frame 3, with the Attacking animation
    Last edited by Nig 13; 07-13-2011 at 09:41 PM.
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    14
    Thanks for your answer, thanks a lot for that code i try to do that and yes Luffy its the best D: when i finish the game i tell you.

    Cya!

  4. #4
    Junior Member
    Join Date
    Jul 2011
    Posts
    14
    Nig one thing, i have the animation for Standing in Left & Standing in Right,

    But that code:

    Actionscript Code:
    if(!Key.isDown(Key.RIGHT) && !Key.isDown(Key.LEFT) && !Key.isDown(49)){ // if none of those keys are being pressed
            gotoAndStop(1); // idle animation (doing nothing, standing)

    its only for 1 animation no? How can i do for detect the position of Luffy?



    Thanks a lot for your help and i think Luffy its the BEST
    Last edited by Jastro; 07-14-2011 at 09:47 AM. Reason: repair text

  5. #5
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Then break up the code to this:

    Actionscript Code:
    if(!Key.isDown(Key.RIGHT) && !Key.isDown(Key.LEFT) && !Key.isDown(49) && _currentframe == 3){ // if none of those keys are being pressed, and the currentframe is 3 (run animation right)
            gotoAndStop(1); // idle animation for right (doing nothing, standing)
        }
        if(!Key.isDown(Key.RIGHT) && !Key.isDown(Key.LEFT) && !Key.isDown(49) && _currentframe == 4){ // if none of those keys are being pressed, and the currentframe is 4 (run animation left)
            gotoAndStop(2); // idle animation for left (doing nothing, standing)
        }

    Anymore questions, feel free to ask
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  6. #6
    Junior Member
    Join Date
    Jul 2011
    Posts
    14
    Again thanks a lot, for now its ok, if i have some any question i tell you


  7. #7
    Junior Member
    Join Date
    Jul 2011
    Posts
    14
    Sorry for double post


    I have some Strange problem with the code, i have some problems i try to explain to you


    - Now when you press Key Right or Key Left, luffy walking so strange, i think he stopping all the time :S

    - When you press "1" the animation of combat repeats all the time :S

    - Now when i use "1" for attack Cocodrile, luffy moves back :S

    - Now i have inside of luffy movieclip 3 its the animation for run to the left, and 4 to the right, but only work if in the code i put animation 3 for left and animation 3 for the right.


    That errors its so strange i added to you my .fla i think i am doing something wrong. Can you see the code and look what i am doing wrong?

    Thanks for your help
    Attached Files Attached Files
    Last edited by Jastro; 07-15-2011 at 07:25 AM. Reason: Wrong writting

  8. #8
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    You know what I did? I rewrote the whole code :P

    It works now, but I don't know if you understand it or not - I've explained some small parts, lol. If you want explanation on some parts, please ask

    ORE WA KAIZOKU OU NI NARU

    PS: I can abit spanish, had classes in 3 years - that's why I understood some parts of your code xD
    Attached Files Attached Files
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  9. #9
    Junior Member
    Join Date
    Jul 2011
    Posts
    14
    Thanks a Lot Nig, now work perfectly, my english its really bad, but if i see the code can i understand more best. Really thanks!

    I LOVE THE NEW SOUND

  10. #10
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Glad you like it

    I put an Attack Sound too, but that caused the Flash to lag (stop) abit when attacking, so I removed it

    Anyways, if you have more questions in the future, please ask, and I'll try my best to help you
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

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