-
Notifications
You must be signed in to change notification settings - Fork 0
/
CCCallLambda.cpp
54 lines (36 loc) · 1.04 KB
/
CCCallLambda.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "CCCallLambda.h"
#include "CCZone.h"
NS_CC_BEGIN
CCCallLambda* CCCallLambda::create(const std::function<void(void)>& func) {
CCCallLambda* pRet = new CCCallLambda();
if (pRet && pRet->initWithLambda(func)) {
pRet->autorelease();
return pRet;
}
CC_SAFE_DELETE(pRet);
return NULL;
}
bool CCCallLambda::initWithLambda(const std::function<void(void)>& func) {
mFunction = func;
return true;
}
CCObject* CCCallLambda::copyWithZone(CCZone *pZone) {
CCZone* pNewZone = nullptr;
CCCallLambda* pRet = nullptr;
if (pZone && pZone->m_pCopyObject) {
pRet = (CCCallLambda*) (pZone->m_pCopyObject);
}
else {
pRet = new CCCallLambda();
pZone = pNewZone = new CCZone(pRet);
}
CCActionInstant::copyWithZone(pZone);
pRet->initWithLambda(mFunction);
CC_SAFE_DELETE(pNewZone);
return pRet;
}
void CCCallLambda::update(float time) {
CCActionInstant::update(time);
mFunction();
}
NS_CC_END