블로그 이미지
박황기
최근에 스마트폰에 관심이 많습니다. 예전에 상상하던 모습들이 점차 이루어지고 있는게 신기하네요.

calendar

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

Notice

2015. 2. 21. 23:20 모바일/COCOS2d

*cocos2d-x v3액션을 실행할때 콜백함수를 호출하는 구문이 변경이 되었다.

예전 방식처럼 하면 실행 할 수가없다.


*공식가이드 참조 : http://www.cocos2d-x.org/programmersguide/4/

An example sequence

auto mySprite = Sprite::create("mysprite.png");

// create a few actions.
auto jump = JumpBy::create(0.5, Vec2(0, 0), 100, 1);

auto rotate = RotateTo::create(2.0f, 10);

// create a few callbacks
auto callbackJump = CallFunc::create([](){
    log("Jumped!");
});

auto callbackRotate = CallFunc::create([](){
    log("Rotated!");
});

// create a sequence with the actions and callbacks
auto seq = Sequence::create(jump, callbackJump, rotate, callbackRotate, nullptr);

// run it
mySprite->runAction(seq);



*call back 함수 3.x관련 참조 

-> 참조 : http://www.programering.com/a/MDNyATMwATc.html


  • CallFunc can be created with an std::function<void()>
  • CallFuncN can be created with an std::function<void(Node*)>
  • CallFuncND and CallFuncO were removed since it can be created with simulated with CallFuncN and CallFunc. See ActionsTest.cpp for more examples

Where: CallFuncND and CallFuncO can be realized by CallFunc and CallFuncN. 

The following examples in detail the two correction action.

1, CallFunc


static CallFunc * create(const std::function<void()>& func);


On the CallFunc example, there are already reflected in the document:

// in v2.1
CCCallFunc *action1 = CCCallFunc::create( this, callfunc_selector( MyClass::callback_0 ) );

// in v3.0 (short version)
auto action1 = CallFunc::create( CC_CALLBACK_0(MyClass::callback_0,this));
auto action2 = CallFunc::create( CC_CALLBACK_0(MyClass::callback_1,this, additional_parameters));

// in v3.0 (long version)
auto action1 = CallFunc::create( std::bind( &MyClass::callback_0, this));
auto action2 = CallFunc::create( std::bind( &MyClass::callback_1, this, additional_parameters));

// in v3.0 you can also use lambdas or any other "Function" object
auto action1 = CallFunc::create(
                 [&](){
                     auto s = Director::sharedDirector()->getWinSize();
                     auto label = LabelTTF::create("called:lambda callback", "Marker Felt", 16);
                     label->setPosition(ccp( s.width/4*1,s.height/2-40));
                     this->addChild(label);
                 }  );


'모바일 > COCOS2d' 카테고리의 다른 글

cocos2d-x 3.x Label Example  (0) 2015.02.18
cocos2dX 2.x to 3.x  (0) 2015.02.01
cocos2d-x 3.3 programing guide  (0) 2015.01.25
COCOS2DX 3.2 설치  (0) 2015.01.18
cocos2d google play game service  (0) 2013.08.09
posted by 박황기