本文整理汇总了C++中CSprite::initWithFile方法的典型用法代码示例。如果您正苦于以下问题:C++ CSprite::initWithFile方法的具体用法?C++ CSprite::initWithFile怎么用?C++ CSprite::initWithFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSprite
的用法示例。
在下文中一共展示了CSprite::initWithFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createLayersContent
void LevelScene::createLayersContent() {
Size winSize = Director::getInstance()->getWinSize();
// create background
CSprite* backgroundFace = new CSprite();
backgroundFace->initWithFile(FRAME_BG);
backgroundFace->setPosition(winSize.width / 2, winSize.height / 2);
this->backgroundLayer->addChild(backgroundFace);
// create level title
CSprite* chapterTitle = new CSprite();
chapterTitle->initWithSpriteFrameName(FRAME_LEVEL_TITLE);
chapterTitle->setPosition(winSize.width / 2, winSize.height - chapterTitle->getContentSize().height / 2 - 20);
this->mainLayer->addChild(chapterTitle);
// create menu
Menu* mainMenu = Menu::create();
mainMenu->setPosition(Point::ZERO);
this->mainLayer->addChild(mainMenu);
// create back button
MenuItemSprite* backButton = CNodeUtil::createButton(FRAME_BACK_BUTTON, FRAME_BACK_BUTTON_SELECTED);
backButton->setCallback(CC_CALLBACK_1(LevelScene::backButtonClick, this));
backButton->setPosition(winSize.width / 2, 20 + backButton->getContentSize().height / 2);
mainMenu->addChild(backButton);
// create level layer
this->levelLayer = Layer::create();
int levelTotal = CONFIG_LEVELS_PER_CHAPTER;
int totalPageSize = ((levelTotal - 1) / CONF_TOTAL_LEVEL_SIZE_PER_PAGE) + 1;
int levelPerPage = CONF_TOTAL_LEVEL_SIZE_PER_PAGE;
int levelPerRow = levelPerPage / CONF_TOTAL_LEVEL_ROW;
int previousLevelTotal = this->getTotalPreviousLevel(this->currentChapter);
this->levelLayer->setContentSize(Size(winSize.width * totalPageSize, winSize.height / 1.5));
this->levelLayer->setPosition(0, winSize.height / 2 - this->levelLayer->getContentSize().height / 2);
this->levelLayerOffset = this->levelLayer->getPosition();
this->mainLayer->addChild(this->levelLayer);
for (int i = 0; i < levelTotal; i++) {
int level = i + 1;
CSprite* levelFace = new CSprite();
int realLevel = level + previousLevelTotal;
// if (gameModel->checkMapLock(realLevel)) {
levelFace->initWithSpriteFrameName(FRAME_BOX_LEVEL);
levelFace->setTag(realLevel);
{
char levelChar[10];
sprintf(levelChar, "%d", level);
Label* levelLabel = CNodeUtil::createLabelTTF(levelChar, 12);
levelLabel->setPosition(levelFace->getContentSize().width / 2, levelFace->getContentSize().height / 2);
levelFace->addChild(levelLabel);
}
// } else {
// levelFace->initWithSpriteFrameName(ANI_BOX_MAP_LOCK);
// levelFace->setTag(-1);
// }
this->levelLayer->addChild(levelFace);
int page = i / levelPerPage;
int row = ((level - (page * levelPerPage)) - 1) / levelPerRow;
int column = i % levelPerRow;
Point pagePosition = Point(winSize.width * page, 0);
float totalWidth = levelFace->getContentSize().width * levelPerRow + (10 * (levelPerRow + 1));
float totalHeight = levelFace->getContentSize().height * CONF_TOTAL_LEVEL_ROW + (10 * (CONF_TOTAL_LEVEL_ROW + 1));
float initX = (winSize.width - totalWidth) / 2;
float initY = this->levelLayer->getContentSize().height - ((this->levelLayer->getContentSize().height - totalHeight) / 2);
float levelPositionX = initX + (10 * (column + 1)) + (levelFace->getContentSize().width / 2 * (column + 1)) + (levelFace->getContentSize().width / 2 * column);
float levelPositionY = initY - (10 * (row + 1)) - (levelFace->getContentSize().height / 2 * (row + 1)) - (levelFace->getContentSize().height / 2 * row);
levelFace->setPosition(Point(levelPositionX, levelPositionY) + pagePosition);
}
}