cocos2d-xcocos2d-x-3.0

scheduleOnce with lambda in cocos2dx v3


void Node::scheduleOnce(const std::function<void(float)> &callback, float delay, const std::string &key)

what the param "key" for?


Solution

  • key, here, is simply a unique string that identifies the lamba being scheduled, as comparing lambda's in c++ rarely has the result you might expect.

    i.e. you can pass the key to other Node methods such as isScheduled to see if the lambda is still scheduled, or unschedule etc.