Quantcast
Channel: Cocos Forums - Latest topics
Viewing all articles
Browse latest Browse all 17124

Windows Keyboard Input

$
0
0

@johnny2d wrote:

How to use CC_CALLBACK_2?

All the example code I have found appears to work without defining CC_CALLBACK_2 or they are showing all their code except code pertaining to CC_CALLBACK_2 definition.

I saw the example code on the cocos2dx site and it doesn’t work. ( I changed KeyboardTest to the class I am using.)

auto listener = EventListenerKeyboard::create();
listener->onKeyPressed = CC_CALLBACK_2(KeyboardTest::onKeyPressed, this);
listener->onKeyReleased = CC_CALLBACK_2(KeyboardTest::onKeyReleased, this);

_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

// Implementation of the keyboard event callback function prototype
void KeyboardTest::onKeyPressed(EventKeyboard::KeyCode keyCode, Event* event)
{
        log("Key with keycode %d pressed", keyCode);
}

void KeyboardTest::onKeyReleased(EventKeyboard::KeyCode keyCode, Event* event)
{
        log("Key with keycode %d released", keyCode);
}

Is this the correct way to make a onkeyPressed listener? The only example code I have found is from several years ago and I’m not sure if this is how to handle key presses in 2019.

Please help

Posts: 4

Participants: 3

Read full topic


Viewing all articles
Browse latest Browse all 17124

Latest Images

Trending Articles



Latest Images