How do I create a MegaMan style charge shot?

Get help using Construct 2

Post » Fri Nov 28, 2014 5:35 am

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
B
9
S
2
Posts: 37
Reputation: 739

Post » Fri Nov 28, 2014 8:37 am

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.
B
41
S
19
G
65
Posts: 1,085
Reputation: 37,842

Post » Fri Nov 28, 2014 12:21 pm

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.
B
72
S
27
G
17
Posts: 254
Reputation: 14,971

Post » Fri Nov 28, 2014 6:26 pm

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

I'll mess around with it when I get home. Thanks!
B
9
S
2
Posts: 37
Reputation: 739

Post » Sat Nov 29, 2014 4:35 am

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
B
9
S
2
Posts: 37
Reputation: 739

Post » Sat Nov 29, 2014 11:10 am

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.
B
72
S
27
G
17
Posts: 254
Reputation: 14,971

Post » Sat Nov 29, 2014 12:12 pm

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?
B
9
S
2
Posts: 37
Reputation: 739

Post » Sat Nov 29, 2014 12:34 pm

Internet explorer 11, chrome and firefox.
B
72
S
27
G
17
Posts: 254
Reputation: 14,971

Post » Sat Nov 29, 2014 12:48 pm

I'm using chrome.

That's incredibly strange. I'll have to test some keyboards.
B
9
S
2
Posts: 37
Reputation: 739


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot], ksiads and 2 guests