(SOLVED) About following and keeping key press

Get help using Construct 2

Post » Mon Jan 27, 2014 4:21 pm

Hi there =)

I'm just newbie in construct 2 :p I just made few tutorials and i don't find any subject about my problem.
I'm making a conversion of maniac shooter and i'm looking for tips ^_^

How can i know if a key on keyboard is pressed during X seconds?
The key is also used to fire and when key is kept press it activate a shield.
When shield is active how should i do to make following or collide the 2 sprites during X seconds ?

Thanks a lot !Teclis012014-01-28 07:58:58
B
8
S
2
Posts: 35
Reputation: 838

Post » Mon Jan 27, 2014 4:57 pm

make a variable called "counting"

add 2 conditions

every x seconds
keyboard is down -> add 1 to "counting" variable

compare variable counting > 3 -> do something.

B
83
S
40
G
15
Posts: 992
Reputation: 16,907

Post » Mon Jan 27, 2014 5:18 pm

It would be easier to create an empty sprite, call it keyboardtimer and give it the timer behaviour.

on key pressed - keyboardtimer start timer "key" for x seconds

on key released - keyboardtimer stop timer "key"

keyboardtimer on timer "key"
- start shield
- keyboardtimer set timer "Shield" for x seconds

keyboardtimer on timer "Shield"
- stop shield

keyboardtimer.capxLittleStain2014-01-27 17:18:47
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Jan 27, 2014 8:38 pm

Thanks for your replies guys :)
I think about my problem a little more, i'm going to try to explain but i'm not event fluent for now in construct :D

So i would like to make that : By pressing fast the fire button, this will activate or help to activate the shield.

OnKeyPressed
if(end+0.2<=now){ // 0.2 is in seconds (0.2s maximum between 2 keyPress)
Timer.begin; // reset of time begin
}

On KeyRelease
Timer.SetEnd(now);

Every 0.1 second
if(begin-end>=1.5){ // 1.5 in seconds
SpawnNewObject(Shield);
}

I think the algorithm is ok how can i translate thoses if statement in event?

Few explanations :

Timer wouls be an object with 2 members (begin and end)

begin represents the most recent time of key pressed (with a rule of buffering if the last one was less or equal to 0.2 seconds before the next one)
end represents the most recent time of key releaseTeclis012014-01-27 20:49:11
B
8
S
2
Posts: 35
Reputation: 838

Post » Mon Jan 27, 2014 9:35 pm

Finally i find how to make that!

Here my solution :

Create Sprite with Timer behaviour
Add 2 variable instance :
begin =0
end=0


Keyboard : on Spacebar released

=>Timer Set end to time

Keybord : on Spacebar is pressed
AND
Timer end <= time-0.2

=>Timer Set begin to time

System / Every 0.1 second
AND
Timer <= Self+1.5

=>Timer Set begin to 0
=>Timer Set end to 0
=>Player Spawn Shield
=> Timer Start Timer "Shield" for 4.0

Timer : on Timer "Shield"
=>Shield destroy

The last thing is to make follow the shield :)Teclis012014-01-27 22:28:41
B
8
S
2
Posts: 35
Reputation: 838


Return to How do I....?

Who is online

Users browsing this forum: Bobbyneal100, Google [Bot], part12studios and 8 guests