cocos2d-x のアクションのテスト〜弾を飛ばす
cocos2d-x のアクションのテスト。
シューティングなどの弾を飛ばす。
ラベルオブジェクトを作って、移動させ、移動完了時に削除する。
基本のシーンの作成は下記URLを参照。
http://nirasan.hatenablog.com/entry/2013/09/23/124822
void GameScene::bombTest() { // 画面サイズの取得 CCSize size = CCDirector::sharedDirector()->getWinSize(); // 発射地点・着弾地点 CCPoint start = ccp(size.width * 0.1, size.height * 0.1); CCPoint end = ccp(size.width * 0.9, size.height * 0.9); // 弾の作成 CCLabelTTF* bomb = CCLabelTTF::create("●", "Arial", 9.0); bomb->setPosition(start); // 弾の移動アクション作成 CCMoveTo* moveAction = CCMoveTo::create(1.0, end); // 着弾時に消えるアクション作成 CCFiniteTimeAction* removeAction = CCCallFuncN::create(this, callfuncN_selector(GameScene::removeBomb)); // 弾が飛んで着弾時に消える一連のアクション作成 CCSequence* seqAction = CCSequence::create(moveTo, remove, NULL)); // 弾の表示とアクション実行 this->addChild(bomb); bomb->runAction(seqAction); } void GameScene::removeBomb(CCNode* sender) { CCLabelTTF* label = (CCLabelTTF*)sender; this->removeChild(label, true); }