(SOLVED) About following and keeping key press

0 favourites
  • 5 posts
From the Asset Store
Random Maze Generator with Door & Key System - tutorial capx
  • 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 !

  • 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.

  • 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.capx

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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 release

  • 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 :)

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