我想在移动延迟后设置正文,我在sprite-kit中搜索类似runBlock的东西。
void MySprite::SpawnSprite( cocos2d::Layer *layer )
{
auto mySprite = Sprite::create();
auto body = PhysicsBody::create();
mySprite->setTexture("MySprite.png");
body->createCircle(arrow->getContentSize().width / 2);
body->setDynamic(false);
mySprite->setPosition( startPoint );
layer->addChild(mySprite);
auto moveTest = MoveTo::create(2, Point(200, 200) );
auto waitAction = DelayTime::create(2);
auto action = Sequence::create(moveTest, waitAction, NULL);//I want to set body after waitAction in sequence(mySprite->setPhysicsBody(body))
mySprite->runAction(action);
}
在sprite-kit中这很简单
runAction(
SKAction.sequence([
action,
SKAction.waitForDuration(2.0),
SKAction.runBlock({ //Set Body }))
])
)
答案 0 :(得分:0)
你需要的是创建CallFuncN并在你的序列中使用它
拳击你需要的功能:
void attachBody(Ref* pSender)
{
Sprite* mySprite = (Sprite*)pSender;
mySprite->setPhysiceBody(body);
//you can do whatever you want to do with your sprite here.
}
现在你的序列将是这样的
auto action = Sequence::create(moveTest, waitAction,CallFuncN::create(CC_CALLBACK_1(attachBody,this)), NULL);
答案 1 :(得分:0)
void MySprite::SetBody(Sprite *sprite)
{
auto body = PhysicsBody::create();
body->createCircle(arrow->getContentSize().width / 2);
body->setDynamic(false);
sprite->setPhysicsBody(body);
}
void MySprite::SpawnSprite( cocos2d::Layer *layer )
{
auto mySprite = Sprite::create();
mySprite->setTexture("MySprite.png");
mySprite->setPosition( startPoint );
layer->addChild(mySprite);
auto moveTest = MoveTo::create(2, Point(200, 200) );
auto waitAction = DelayTime::create(2);
auto funcCallAction = CallFunc::create([=](){
MySprite::SetBody(mySprite);
});
auto action = Sequence::create(moveTest, waitAction, funcCallAction, NULL);
mySprite->runAction(action);
}