本文整理汇总了C++中CSprite::setPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ CSprite::setPosition方法的具体用法?C++ CSprite::setPosition怎么用?C++ CSprite::setPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSprite
的用法示例。
在下文中一共展示了CSprite::setPosition方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
void PlayState::init()
{
vertical = 1;
count = 0;
background = new CImage();
background->loadImage("data/maps/black.png");
while(count != 7){
CSprite* enemy = new CSprite();
enemy->loadSpriteSparrowXML("data/img/bug.xml");
if(count > 2) vertical = 3;
enemy->setPosition((count%3)*125,50*vertical);
enemy->setAnimRate(0);
enemies[count] = enemy;
count++;
}
player = new CSprite();
player->loadSpriteSparrowXML("data/img/spaceship.xml");
player->setPosition(172,550);
player->setAnimRate(0);
dirx = 0; // direção do personagem: para a direita (5), esquerda (-5)
diry = 0; // direção do personagem: para cima (5), baixo (-5)
keyState = SDL_GetKeyState(0); // get key state array
cout << "PlayState Init Successful" << endl;
}
示例2: update
void update(Ogre::Real tpf) {
if (m_bVisible) {
m_Indicator.setPosition(getPosition());
m_Indicator.getTexture().setTexturePosRight(m_fValue);
m_Indicator.setSize(Ogre::Vector2(m_fValue * m_vSize.x, m_vSize.y));
CSprite::update(tpf);
}
}
示例3: addSpriteToLayer
void LevelScene::addSpriteToLayer(Obj* object, Layer* layer, int index) {
for (int i = 0; i < object->getSprites()->size(); i++) {
CSprite* cSprite = (CSprite*) object->getSprites()->at(i);
cSprite->setPosition(object->getPosition());
cSprite->setAnchorPoint(object->getBody()->getAnchorPoint());
cSprite->setFlippedX(object->getBody()->getFlipX());
layer->addChild(cSprite, index);
}
}
示例4: updatePsiFieldPosition
//Synchronizes the unit's psi field sprite position with the unit.
void updatePsiFieldPosition(const CUnit *unit) {
if (!unit || !unit->sprite || !unit->building.pylonAura) return;
CSprite *psiField = unit->building.pylonAura;
if (unit->sprite->position != psiField->position) {
//for (CImage *i = psiField->imageHead; i; i = i->link.next)
// i->flags |= 1; //Redraw image
psiField->setPosition(unit->getX(), unit->getY());
refreshSpriteData(psiField);
*canUpdatePoweredStatus = true;
}
}
示例5: 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);
}
}
示例6: init
bool CUpdateLogView::init(CGameUpdateScene *updataScene,bool isUpdate)
{
m_updataScene = updataScene;
m_isUpdate = isUpdate;
if( !CContainer::init() )
return onInitialized(false);
CCSize winSize = CCDirector::sharedDirector()->getVisibleSize();
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("General.plist");
CSprite *pBackground = CSprite::createWithSpriteFrameName("general_first_underframe.png", CCRectMake(75.0f, 75.0f, 25.0f, 25.0f));
pBackground->setPreferredSize(CCSizeMake(600,500));
pBackground->setPosition(ccp(winSize.width/2.0f+30.0f, winSize.height/2.0f + 50.0f));
addChild(pBackground);
CSprite *pTitleImg = CSprite::create("loginResources/signs_word_yxgxgg.png");
pTitleImg->setControlName("this CUpdateLogView pTitleImg 81");
pTitleImg->setPosition(ccp( winSize.width/2.0f+30.0f, winSize.height/2.0f + 255 ));
addChild(pTitleImg);
//webView
CCSize screenSize = CDevice::sharedDevice()->getScreenSize();
m_pWebView = CWebView::create();
CCSize mySize;
#if( CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
mySize = CCSizeMake(screenSize.height, screenSize.width);
#elif( CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
mySize = CCSizeMake(screenSize.width, screenSize.height);
#endif
CCSize bgSize = pBackground->getPreferredSize();
CCSize viewSize = CCSizeMake(mySize.width / winSize.width * (bgSize.width-40) , mySize.height / 640 * bgSize.height*0.68f);
m_pWebView->setPreferredSize(viewSize);
m_pWebView->setPosition(ccp( mySize.width/2-viewSize.width/2+30.0f/winSize.width*mySize.width,100.0f/winSize.height*mySize.height ));
addChild(m_pWebView);
//添加 进入按钮
m_pGoInBtn = CButton::createWithSpriteFrameName("进入游戏", "general_button_normal.png");
CCSize buttonSize = m_pGoInBtn->getPreferredSize();
m_pGoInBtn->setPosition(ccp(winSize.width/2.0f+30.0f,winSize.height*0.25f));
m_pGoInBtn->addEventListener("TouchBegan", this, eventhandler_selector(CUpdateLogView::onBeganTouchGoInButton));
addChild(m_pGoInBtn);
char szUrl[1024];
__getUrl(szUrl);
m_pWebView->loadGet(szUrl);
if(m_isUpdate)
{
m_pGoInBtn->setTouchesEnabled( false );
m_pWebView->loadGet(szUrl, NULL, NULL, 0U, this , eventhandler_selector(CUpdateLogView::onUpdateLogLoaded));
CCLOG(" CUpdateLogView %s",szUrl);
}
return onInitialized(true);
}
示例7: AddAtoms
void CInventory::AddAtoms(char* i_strAtomSymbol, int i_nCount)
{
bool bMatchFound = false;
int matchIndex = -1;
if (inventoryCount == 0)
{
// HASAN - debug
//s3eDebugOutputString("Adding inventory sprite to sprite manager.");
// add the inventory to the sprite manager when the first atom is added
g_Game.getSpriteManager()->addSprite(inventory_sprite);
}
if (inventoryCount > 0)
{
for (int i = 0; i < MAX_COUNT; i++)
{
if (!strcmp(atoms[i], i_strAtomSymbol))
{
bMatchFound = true;
matchIndex = i;
break;
}
}
}
if (!bMatchFound)
{
// match
strcpy(atoms[inventoryCount], i_strAtomSymbol);
atomCount[inventoryCount] += i_nCount;
CAtom* atom = new CAtom();
atom->Init(i_strAtomSymbol);
// horizontal center, same as inventory graphic
int posX = (Iw2DGetSurfaceWidth() / 2) - (IMAGE_SIZE_WIDTH / 2);
int posY = Iw2DGetSurfaceHeight() - (IMAGE_SIZE_HEIGHT / 2);
// offset inventory horizontally to fit in the container
posX = posX + (10 + (64 / 2)); // NOTE: 64 = atom size, 10 = border + spacing
if (inventoryCount > 0)
{
posX = posX + (inventoryCount * (64 + 15)); // NOTE: 64 = atom size, 15 = spacing + border + spacing
}
atom->setPosAngScale(posX, posY, 0, IW_GEOM_ONE);
atom->setVelocity(0,0);
// HASAN - new to create/show the inventory count images
CIw2DImage* inventoryCountImage = Iw2DCreateImageResource("inventory_number");
CSprite* inventoryCountSprite = new CSprite();
inventoryCountSprite->setImage(inventoryCountImage, "inventory_number");
// NOTE: image width & height = 25 & font width & height = 30
inventoryCountSprite->setPosition(posX + 13 + (30 / 2), posY + (30 / 2) + 3);
inventoryCountSprite->setDestSize(30, 30); // make larger than source to fit behind the text properly
g_Game.getSpriteManager()->addSprite(inventoryCountSprite);
atomCountImages[inventoryCount] = inventoryCountSprite;
atomObjs[inventoryCount] = atom;
inventoryCount++;
}
else
{
atomCount[matchIndex] += i_nCount;
}
}