Cocos2D-X keyboard hold key

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

  • Lukus

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

    • metin

      thx for sharing your idea, you are right will definitely be faster 🙂

  • Jonathan

    good idea!

    Thank you!

Recent Posts

Recent Comments