A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: Character only performing actions in Air?

  1. #1
    Member
    Join Date
    Dec 2003
    Posts
    35

    Character only performing actions in Air?

    Hi all.

    I've been following the Platforms tutorial on this site to make a good platform game. I got everything the tutorial taught down just fine, so no problems there. The problems start when I try to add somethings of my own.

    I added it so that when I push ENTER my character attacks, but he only seems to do it when he's in the air. Also, I made it so holding SHIFT makes him run faster, and still only does it while in the air. If your standing on the ground or platform he doesn't perform the action.

    Any ideas? If I need to post the actionscript or give any other info please let me know. All help appreciated, thanks.

  2. #2
    ·»¤«· >flashl!ght<'s Avatar
    Join Date
    Jun 2003
    Posts
    746
    yes please post the AS. this is a very circumstancial bug, i can barely even start to guess what has caused this error. (besides the obvious, that is sounds like the script you added is somewhow nested in the wrong place; namely, in the jump/ if(flying) script)

    preferably, post up the FLA. we'll get u straight
    >flashl!ght<
    All the normal names were taken.
    Ron Paul was right.

  3. #3
    Member
    Join Date
    Dec 2003
    Posts
    35
    Alright, Thanks.

    I'm still very new to making games in flash, so please let me know if I did something very wrong.

    I'm using the "Create a SImple Platform Game" Tutorial as my guide for building this.

    My Character is Hero, and the Platforms/ground are MC "Platforms" and the walls are "leftwall" and "rightwall". The action i'm trying to do on the ground is "ENTER" to attack.

    Ok, here is the code.
    ----------------------------------

    onClipEvent (load) {
    gravity = 10;
    scale = _xscale;
    walkSpeed = 6;
    maxjump = 6;
    }
    onClipEvent (enterFrame) {
    if (air == true) {
    _y += gravity;
    state = 3;
    }
    if (Key.isDown(Key.LEFT) && !_root.leftwall.hitTest(_x, _y, true)) {
    _x -= walkSpeed;
    _xscale = -scale;
    }
    if (Key.isDown(Key.RIGHT) && !_root.rightwall.hitTest(_x, _y, true)) {
    _x += walkSpeed;
    _xscale = scale;
    }
    if (_root.platforms.hitTest(_x, _y, true)) {
    air = false;
    } else {
    air = true;
    }
    if (Key.isDown(Key.SPACE) && jump == true) {
    _y -= jumpSpeed;
    }
    if (air == false) {
    jump = true;
    jumpcount = 0;
    jumpSpeed = 22;
    }
    if (Key.isDown(Key.SPACE)) {
    jumpcount += 1;
    }
    if(Key.isDown(Key.CONTROL)){
    gravity = 2;
    state = 4;
    }else{
    gravity = 10;
    }
    if(key.isDown(Key.ENTER)){
    state = 5;
    }
    if (jumpcount>maxjump && jumpSpeed>-2) {
    jumpSpeed -= 2;
    }
    if (air == false && !Key.isDown(Key.LEFT) && !Key.isDown(65) && _currentframe<4 or air == false && !Key.isDown(Key.RIGHT) && !Key.isDown(65) && _currentframe<4) {
    state = 1;
    }
    if (Key.isDown(Key.LEFT) && air == false && !Key.isDown(65) && _currentframe<4 or Key.isDown(Key.RIGHT) && air == false && !Key.isDown(65) && _currentframe<4) {
    state = 2;
    }
    if (!Key.isDown(65)) {
    gotoAndStop(state);
    }
    _root.statetxt = state;
    }
    onClipEvent (keyUp) {
    if (Key.getCode() == 83) {
    jump = false;
    }
    }
    ------------------------------------

    Thanks for any help. If you still need it, I'll post the fla file.
    Last edited by Atomsk; 09-25-2004 at 03:09 PM.

  4. #4
    Junior Member
    Join Date
    Sep 2004
    Posts
    23
    I can help but you need to post the SWF or if you want, the FLA so I can see whats going on.

  5. #5
    Senior Member dogtown08's Avatar
    Join Date
    Jul 2004
    Location
    In a later dimension
    Posts
    201
    code:
    if (air == false && !Key.isDown(Key.LEFT) && !Key.isDown(65) && _currentframe<4 or air == false && !Key.isDown(Key.RIGHT) && !Key.isDown(65) && _currentframe<4) {
    state = 1;
    }
    if (Key.isDown(Key.LEFT) && air == false && !Key.isDown(65) && _currentframe<4 or Key.isDown(Key.RIGHT) && air == false && !Key.isDown(65) && _currentframe<4) {
    state = 2;
    }

    It would help a little more if you say what all the states are, but the actionscript is probably the problem.

    When you see a "!" it usually means "not" or "opposite". So, anywhere you see "if(Key.isDown(Key.(any key))" it means if a key is not down, run the code. In the code above, it checks to see if no keys are down. Probably what you need to do is add
    code:
     && !Key.isDown(Key.ENTER)



    add it immediately before the last ")" in both statements. The final code should look like:

    code:
    if (air == false && !Key.isDown(Key.LEFT) && !Key.isDown(65) && _currentframe<4 or air == false && !Key.isDown(Key.RIGHT) && !Key.isDown(65) && _currentframe<4 && !Key.isDown(Key.ENTER)) {
    state = 1;
    }
    if (Key.isDown(Key.LEFT) && air == false && !Key.isDown(65) && _currentframe<4 or Key.isDown(Key.RIGHT) && air == false && !Key.isDown(65) && _currentframe<4 && !Key.isDown(Key.ENTER)) {
    state = 2;
    }

    Last edited by dogtown08; 09-25-2004 at 04:48 PM.

  6. #6
    Member
    Join Date
    Dec 2003
    Posts
    35
    Your right, I'm sorry. I should have posted the states.

    State1 = Standing Still

    State2 = walking

    State3 = jumping

    State4 = Umbrella (causes him to fall slowly)

    State5 - The Attack one (this is the one I want ENTER to play).

    Thanks for the help, but I added those lines of code and it didn't seem to help. He still just pulls it out in the air only. Any other suggestions?

    One other question (for now). What does that !Key.isDown(65) command mean? The tutorial didn't explain it, so I'm not sure what the "65" is for. Thanks.
    Last edited by Atomsk; 09-25-2004 at 05:10 PM.

  7. #7
    self-portrait Kianis's Avatar
    Join Date
    Feb 2004
    Location
    Stockholm, Sweden
    Posts
    425
    [off topic]
    Are you Atomsk from Anitude? :P
    [/off topic]

  8. #8
    Member
    Join Date
    Dec 2003
    Posts
    35
    Antitude?

    Never heared of it, sorry.

  9. #9
    Senior Member dogtown08's Avatar
    Join Date
    Jul 2004
    Location
    In a later dimension
    Posts
    201
    Ok, make it easy. Take out the line "state=5" and replace it with "gotoAndStop(5)"

    If that doesn't work, please post a fla (in MX format if you have MX 2004)

  10. #10
    the Dervish of Q??
    Join Date
    Mar 2004
    Location
    Abbotsford, BC
    Posts
    103
    I'm guessing 65 is the internal code used for space. Basically the equivalent of writing
    code:
    if(Key.isDown(Key.SPACE));


    I'm not sure what's wrong with it, what dogtown08 said should've cleared it up. BUT I think I see where you need to add that line. At the end of the bracket and right before the or in each line, add
    code:

    && !Key.isDown(Key.ENTER)


    That should clear it up entirely. If it doesn't, fla us.

    Hope this helps.

    Derek

  11. #11
    Member
    Join Date
    Dec 2003
    Posts
    35
    Thanks you guys! I got it working!

    I added the && Key.isDown(Key.ENTER) like you said, but it still didn't work. So I also added:

    if (air == false && Key.isDown(Key.ENTER)){
    state = 5;}

    if (air == false && !Key.isDown(Key.ENTER)){
    state = 1;}

    And that got it all working! So thanks for all your help!

    >___> but I have another question if you don't mind.

    Now that his attack works, I wanna make it able to actually hurt enemies. However, I can only seem to find tutorials for attacks with guns and lasers. Is the code generally the same for Melee attacking? If not, could you point me to a good tutorial for it?

    I appreciate it.

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