本文整理汇总了C++中Star::setOpacity方法的典型用法代码示例。如果您正苦于以下问题:C++ Star::setOpacity方法的具体用法?C++ Star::setOpacity怎么用?C++ Star::setOpacity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Star
的用法示例。
在下文中一共展示了Star::setOpacity方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: starsUpdate
void GameScene::starsUpdate(float dt)
{
int chance = rand() % Star::chance;
Size visibleSize = Director::getInstance()->getVisibleSize();
if (chance == 0)
{
Star * star = Star::create(cocos2d::Vec2(visibleSize.width * 1.03, 100 + rand() % (int)(visibleSize.height * 0.8)));
star->setScale(0.2f + (rand() % 8) / 10.f);
star->setOpacity(50 + (rand() % 200));
this->addChild(star, Layers::SECOND_PLAN);
vecStars.push_back(star);
}
for (unsigned int iStar = 0; iStar < vecStars.size(); ++iStar)
{
if (vecStars[iStar] != nullptr)
{
if (vecStars[iStar]->getIsValid())
{
vecStars[iStar]->update(dt);
}
else
{
if (vecStars[iStar]->getParent() != nullptr)
vecStars[iStar]->getParent()->removeChild(this);
}
}
else
{
std::swap(vecStars[iStar], vecStars[vecStars.size() - 1]);
vecEnemies.pop_back();
}
}
}
示例2: addStars
void GameLayer::addStars(void) {
Star * star;
//number of stars and boosts to add to this level
_numStars = _manager->getTotalStars();
int numBoosts = _manager->getBoostNumber();
int cnt = 0;
int i = 0;
int index;
CCPoint starPosition;
CCPoint position;
while (cnt < _numStars) {
starPosition = _manager->starPosition(i);
i++;
//grab stars array index based on selected Grid Cell
index = starPosition.y * _manager->getColumns() + starPosition.x;
if (index >= STARS_IN_POOL) {
continue;
}
//grab position from selected Grid Cell
position.x = starPosition.x * TILE;
position.y = _screenSize.height - starPosition.y * TILE;
//don't use cells too close to moon perch
if (fabs(position.x - _moonStartPoint.x) < _moon->getRadius() * 2 &&
fabs(position.y - _moonStartPoint.y) < _moon->getRadius() * 2) {
continue;
}
//grab star from pool
star = (Star *) _manager->starFromPool(index);
if (star->getParent()) star->removeFromParentAndCleanup(false);
if (star->getOpacity() != 255) star->setOpacity(255);
//add boosts first, if any
if ( cnt >= _numStars - numBoosts) {
star->setValues(position, true);
} else {
star->setValues(position, false);
}
_gameBatchNode->addChild(star, kMiddleground);
star->setVisible(true);
cnt++;
}
}
示例3: init
// on "init" you need to initialize your instance
bool GameScene::init()
{
CCLOG("GAME SCENE START");
srand((int)std::time(NULL));
if (!MainScene::init())
{
return false;
}
world = new b2World(b2Vec2(0.f, 0.f));
// HERE STARTS THE MAGIC
scheduleUpdate();
mState = States::S_GAME;
Vec2 origin = Director::getInstance()->getVisibleOrigin();
Size visibleSize = Director::getInstance()->getVisibleSize();
// Background
mBackground = Sprite::create("backgrounds/gameBackground.png");
mBackground->setPosition(Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2));
this->addChild(mBackground, Layers::BACKGROUND);
// Player
mPlayer = Player::create(Vec2(400.f, 400.f), world);
this->addChild(mPlayer, Layers::PLAYER);
mapKeysPressed[EventKeyboard::KeyCode::KEY_UP_ARROW] = false;
mapKeysPressed[EventKeyboard::KeyCode::KEY_RIGHT_ARROW] = false;
mapKeysPressed[EventKeyboard::KeyCode::KEY_LEFT_ARROW] = false;
mapKeysPressed[EventKeyboard::KeyCode::KEY_DOWN_ARROW] = false;
// Create starry background which moves
for (unsigned int i = 0; i < 100; ++i)
{
Star * star = Star::create(cocos2d::Vec2(50.f + rand() % (int)(visibleSize.width), 50.f + rand() % (int)(visibleSize.height * 0.9f)));
star->setScale(0.2f + (rand() % 6) / 10.f);
star->setOpacity(50 + (rand() % 200));
this->addChild(star, Layers::SECOND_PLAN);
vecStars.push_back(star);
}
// Assign Box2D contact listener to world
CL = new ContactListener;
world->SetContactListener(CL);
// Points
pointsLabel = Label::createWithTTF("Score: " + std::to_string(points), "fonts/DKCoolCrayon.ttf", 25.f);
pointsLabel->setPosition(10 + pointsLabel->getBoundingBox().size.width / 2, 20);
this->addChild(pointsLabel, Layers::GUI);
mGameOverInfo = Label::createWithTTF("Game Over\nScore: " + std::to_string(points), "fonts/DKCoolCrayon.ttf", 50.f);
mGameOverInfo->setPosition(visibleSize.width / 2.f, visibleSize.height / 2.f);
mGameOverInfo->setAlignment(cocos2d::TextHAlignment::CENTER);
mGameOverInfo->setOpacity(0);
this->addChild(mGameOverInfo, Layers::GUI);
// Bars
mHpBarBorder = Sprite::create("gui/BarBorder.png");
mRageBarBorder = Sprite::create("gui/BarBorder.png");
mHpBarFill = Sprite::create("gui/HpBarFill.png");
mRageBarFill = Sprite::create("gui/RageBarFill.png");
mRageBarFill->setTextureRect(cocos2d::Rect(0.f, 0.f, 0.f, mRageBarFill->getBoundingBox().size.height));
mRageBarFill->setAnchorPoint(Vec2(0.f, 0.5f));
mRageBarBorder->setAnchorPoint(Vec2(0.f, 0.5f));
mHpBarBorder->setAnchorPoint(Vec2(0.f, 0.5f));
mHpBarFill->setAnchorPoint(Vec2(0.f, 0.5f));
mHpBarBorder->setPosition(100.f, visibleSize.height - 30.f);
mRageBarBorder->setPosition(350.f, visibleSize.height - 30.f);
mHpBarFill->setPosition(100.f, visibleSize.height - 30.f);
mRageBarFill->setPosition(350.f, visibleSize.height - 30.f);
this->addChild(mHpBarFill, Layers::GUI);
this->addChild(mRageBarFill, Layers::GUI);
this->addChild(mHpBarBorder, Layers::GUI);
this->addChild(mRageBarBorder, Layers::GUI);
time = 0.f;
return true;
}
示例4: createHelpScreen
void HelpLayer::createHelpScreen () {
_bgLight = CCSprite::create("bg_light.jpg");
_bgLight->setPosition(ccp(_screenSize.width * 0.5f, _screenSize.height * 0.5f));
this->addChild(_bgLight, kBackground);
_bgLight->setVisible(false);
_bgLight->setOpacity(0);
_bgDark = CCSprite::create("bg_dark.jpg");
_bgDark->setPosition(ccp(_screenSize.width * 0.5f, _screenSize.height * 0.5f));
this->addChild(_bgDark, kBackground);
_gameBatchNode = CCSpriteBatchNode::create("sprite_sheet.png", 800);
this->addChild(_gameBatchNode, kMiddleground);
_moonPerch = CCSprite::createWithSpriteFrameName("moon_perch.png");
_moonPerch->setPosition(_moonStartPoint);
_moonPerch->setOpacity(50);
_gameBatchNode->addChild(_moonPerch, kBackground);
CCSprite * ground = CCSprite::createWithSpriteFrameName("ground.png");
ground->setAnchorPoint(ccp(0,0));
_gameBatchNode->addChild(ground, kForeground);
_moon = Moon::create();
_moon->setPosition(_moonStartPoint);
_moon->setNextPosition(_moonStartPoint);
_gameBatchNode->addChild(_moon, kMiddleground);
_sun = Sun::create();
_sun->setPosition(ccp(_screenSize.width * 0.5, -_sun->getRadius()));
_sun->setNextPosition(ccp(_screenSize.width * 0.5, -_sun->getRadius()));
_sun->setVisible(false);
_gameBatchNode->addChild(_sun, kMiddleground);
_boostHitParticles = CCParticleSystemQuad::create("boost_hit.plist");
_lineHitParticles = CCParticleSystemQuad::create("line_burst.plist");
_groundHitParticles = CCParticleSystemQuad::create("off_screen.plist");
_starHitParticles = CCParticleSystemQuad::create("star_burst.plist");
_boostHitParticles->stopSystem();
_lineHitParticles->stopSystem();
_groundHitParticles->stopSystem();
_starHitParticles->stopSystem();
this->addChild(_boostHitParticles);
this->addChild(_lineHitParticles);
this->addChild(_groundHitParticles);
this->addChild(_starHitParticles);
_drawLayer = DrawLayer::create();
this->addChild(_drawLayer, kForeground);
_sun->setPosition(ccp(_screenSize.width * 0.5f, -_sun->getRadius()));
_sun->setNextPosition(ccp(_screenSize.width * 0.5f, -_sun->getRadius()));
_sun->setVisible(false);
_sun->reset();
//reset moon and perch
_moon->setPosition(_moonStartPoint);
_moon->setNextPosition(_moonStartPoint);
_moon->reset();
_moonPerch->setOpacity(50);
_starsCollected = false;
_drawLayer->setStartPoint(ccp(0,0));
_drawLayer->setTouchPoint(ccp(0,0));
_bgDark->setOpacity (255);
_bgLight->setOpacity(0);
_starsUpdateIndex = 0;
_starsUpdateRange = 10;
_starsUpdateInterval = 5;
_starsUpdateTimer = 0.0;
//add stars
Star * star;
//number of stars and boosts to add to this level
_numStars = 5;
int numBoosts = 1;
int cnt = 0;
int i = 0;
int index;
CCPoint starPosition;
CCPoint position;
while (cnt < _numStars) {
starPosition = _manager->starPosition(i);
i++;
//.........这里部分代码省略.........