Lincoln Law wrote:
> I’ve found some way to do that recently but it needs c**11 support enabled. Cococ2d-x still has some problems compiling with c**11-support.
hey dudes,just show me how,thanks
I’ll show but this won’t work until cocos2d-x gains compatibility with c++11. The code below may contain mistakes since I’ve made a major cleanup to my game since I’ve tested it and now I’m writing it from my memory.
CCTimer *t = CCTimer::timerWithTarget(CCScheduleCallback::create(std::function((float dt)
// your code here
// any variables you need to capture from context need to be listed in square brackets above
})), schedule_selector(CCScheduleCallback::execute), 1);
CCScheduleCallback (and classes for other kinds of callbacks) is defined like this:
class CCScheduleCallback : public CCObject
static CCScheduleCallback* create(std::function tFunc)
CCScheduleCallback* pRet = new CCScheduleCallback();
pRet->m_tFunc = tFunc;
void execute(float dt)
You’ll need to prevent CCScheduleCallback object you pass as target from being destroyed before the selector is executed in case it won’t be executed immediatelly (need non-autorelease constructor and manual release?).