Cocos2D-X keyboard hold key

Here is how I handle keyboard onkeyHold in cocos2dx, if someone has a better method please share it.

3 responses to “Cocos2D-X keyboard hold key”

  1. Lukus says:

    Hi, maybe instead of storing it in the vector, you could also just introduce bool variables bIsEnterPressed, bIsLeftArrowPressed, … and modify them accordingly. Could be faster and more readable.

    if (bIsUpKeyPressed)

    instead of

    if(std::find(heldKeys.begin(), heldKeys.end(), UP_ARROW) != heldKeys.end())

    the other method will be of course longer with switch statement or something..

  2. Jonathan says:

    good idea!

    Thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *