How do I create a MegaMan style charge shot?

0 favourites
  • 9 posts
From the Asset Store
Shoot balls to destroy as many blocks as possible, at each stage the game will become more difficult.
  • Hey all!

    I'm trying to make a character able to fire three different types of bullets depending on how long they hold the space button down.

    I have a "Player" sprite with a "Charging" numeric instance variable and a "Charge" sprite with animations "Idle", "Charging1", "Charging2", and "Charging3".

    What I have right now is:

    | Keyboard - Space is down . . . . | Charge - Set animation to "Charging1"

    | Player - Charging = 0 . . . . . . . . | Player - Set Charging to 1

    | | . . . . . . . . . . . . . . . . . . . . . . . . . |System - Wait 2.5 seconds

    | |

    | | Keyboard - Space is down . . | Charge - Set animation to "Charging2"

    | | Player - Charging = 1 . . . . . . . | Player - Set Charging to 2

    | | | . . . . . . . . . . . . . . . . . . . . . . . . | System - Wait 3.5 seconds

    | | |

    | | | Keyboard - Space is down . . . | Charge - Set animation to "Charging3"

    | | | Player - Charging = 2 . . . . . . . .| Player - Set Charging to 3

    Also, above that, I have:

    | Keyboard - On Space released . . . . | Player - Set Charging to 0.

    This works in that when the player holds down the Space bar, the Charge sprite goes through the proper animations at the pace I want, but if the player quickly presses space repeatedly for a bit before holding the space button, the Charge sprite animation jumps straight to "Charging2" and doesn't change after.

    I know that's because the events have the System Wait postponements in them, and I'm having a bit of trouble trying to make it work.

    Can anyone help me with this?

    Thanks!

    Scott

  • If you're going to do it that way, try adding a Timer behavior to your player and use the timer events instead, because with that you can cancel the timer when the space key is released so that this issue is avoided.

  • Instead of using the wait action, try doing it with a timer like Promient says. You can use the behavior or use your own timing using a global or instance variable. For example, when the space bar is down, every 0.1 seconds add 0.1 to the variable, and reset this value every time the spacebar is pressed (trigger).

    Then you can just do the actions depending on the value of the variable, if's it's below 2.5, between 2.5 and 3.5...etc.

  • Ah, I didn't realize there was a timer behavior.

    I'll mess around with it when I get home. Thanks!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • So I got the charge button working, but now for some reason, when I hold down space and move left I can't jump.

    I can move right and hold space and jump at the same time, but just not left.

    Anyone have any ideas?

    Here's the .Capx:

    https://www.dropbox.com/s/g3fl34vlemear ... .capx?dl=0

  • It works for me. Maybe it's your keyboard? I know some keyboards have limitations and you can't have a lot of keys pressed at the same time.

  • That's weird.

    If that were the case, wouldn't it be the same while I were moing right?

    Can I ask which browser you previewed it on?

  • Internet explorer 11, chrome and firefox.

  • I'm using chrome.

    That's incredibly strange. I'll have to test some keyboards.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)