本文整理汇总了C++中BackgroundLayer类的典型用法代码示例。如果您正苦于以下问题:C++ BackgroundLayer类的具体用法?C++ BackgroundLayer怎么用?C++ BackgroundLayer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BackgroundLayer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: removeCoin
void PlayScene::removeCoin(cpSpace * space, void * key, void * data)
{
PlayScene *This = static_cast<PlayScene *>(data);
BackgroundLayer *backgroundLayer =
This->m_gameLayer->getChildByTag<BackgroundLayer *>(LAYER_BACKGROUND);
backgroundLayer->removeObjectByShape(static_cast<cpShape *>(key));
}
示例2:
void BuyLifeLayer::onCommandBuy130(CCObject * pSender)
{
SimpleAudioEngine::sharedEngine()->playEffect(g_sSelectedSound);
BackgroundLayer* layer = (BackgroundLayer*)GameScene::sharedGameScene()->getBackgroundLayer();
if (layer->subGoldCount(500))
addLifeCount(130);
else
GameScene::sharedGameScene()->showBuyGoldLayer();
}
示例3: getPhysicsBody
bool HeroSprite::onContactBegin(PhysicsContact& contact) {
if (mState == STATE_DEAD) {
return false;
}
if (hitTest(contact, TAG_HERO_PHYS_BODY|TAG_GROUND1_PHYS_BODY)) {
Vec2 v = getPhysicsBody()->getVelocity();
getPhysicsBody()->setVelocity(Vec2(0, 0));
getPhysicsBody()->resetForces();
getPhysicsBody()->setContactTestBitmask(1<<1);
if ((mState == STATE_JUMP1)
|| (mState == STATE_JUMP2)
|| (mState == STATE_IDLE)) {
if (v.y < -200)
stand();
else
mState = STATE_STAND;
CallFunc *callback = CallFunc::create([&]() {
run();
});
auto delay = DelayTime::create(0.05f);
auto seq = Sequence::create(delay, callback, nullptr);
runAction(seq);
}
}
if (hitTest(contact, TAG_HERO_PHYS_BODY|TAG_BARRIER_PHYS_BODY)) {
BackgroundLayer * bg = (BackgroundLayer *)(getScene()
->getChildByName("gamelayer")
->getChildByName("background"));
bg->stopMove();
auto scale1 = ScaleTo::create(0.1, 0.9, 0.9);
auto scale2 = ScaleTo::create(0.1, 1.0, 1.0);
auto seq1 = Sequence::create(scale1, scale2, nullptr);
getNodeByTag(contact, TAG_BARRIER_PHYS_BODY)->runAction(seq1);
getPhysicsBody()->setContactTestBitmask(1<<1 | 1<<0);
dead();
CallFunc *callback = CallFunc::create([]() {
Director::getInstance()->replaceScene(GameOverScene::create());
});
auto seq = Sequence::create(DelayTime::create(1), callback, nullptr);
runAction(seq);
EventCustom event("EVENT_GameOver");
_eventDispatcher->dispatchEvent(&event);
}
return true;
}
示例4: new
BackgroundLayer* BackgroundLayer::create(BgLayerDef* bgLayerDef) {
BackgroundLayer* backgroundLayer = new (std::nothrow) BackgroundLayer();
if (backgroundLayer && backgroundLayer->init(bgLayerDef)) {
backgroundLayer->autorelease();
return backgroundLayer;
}
CC_SAFE_DELETE(backgroundLayer);
return nullptr;
}
示例5: cullEmptyLayers
void BackgroundLayer::cullEmptyLayers()
{
BackgroundLayer *next;
for (BackgroundLayer *p = this; p; p = next) {
next = p->m_next;
if (next && !next->isBackgroundImageSet() &&
!next->isBackgroundXPositionSet() && !next->isBackgroundYPositionSet() &&
!next->isBackgroundAttachmentSet() && !next->isBackgroundClipSet() &&
!next->isBackgroundCompositeSet() && !next->isBackgroundOriginSet() &&
!next->isBackgroundRepeatSet() && !next->isBackgroundSizeSet()) {
delete next;
p->m_next = 0;
break;
}
}
}
示例6: new
BackgroundLayer *BackgroundLayer::create(
std::string baseBackgroundImgFilename,
std::string baseMaskImgFilename,
int rStart, int rEnd, int cStart, int cEnd) {
BackgroundLayer *pRet = new(std::nothrow) BackgroundLayer(
baseBackgroundImgFilename, baseMaskImgFilename,
rStart, rEnd, cStart, cEnd);
if (pRet && pRet->init()) {
pRet->autorelease();
return pRet;
}
else {
delete pRet;
pRet = nullptr;
}
return nullptr;
}
示例7: initScene
/**
* @brief Map::initScene creates the scene with a margin around the background image. Requires
* BackgroundLayer to be initiated
* @param tileStep
*/
void Map::initScene(int tileStep) {
int sceneHeight, sceneWidth;
BackgroundLayer *bgLayer = dynamic_cast<BackgroundLayer *>(
m_Layers->getLayer(LayerCodes::LAYER_BACKGROUND)
);
if (tileStep < 5) {
tileStep = 5;
}
sceneHeight = bgLayer->getBackground()->rect().height()
+ BG_OFFSET * tileStep;
sceneWidth = bgLayer->getBackground()->rect().width()
+ BG_OFFSET * tileStep;
initScene(sceneWidth, sceneHeight);
}
示例8: init
bool MainScene::init()
{
CCScene::init();
BackgroundLayer* background = BackgroundLayer::create();
background->setTag(LAYER_BACKGROUND);
addChild(background);
LandsLayer* lands = LandsLayer::create();
lands->setTag(LAYER_LANDS);
addChild(lands);
PlayerLayer* playerLayer = PlayerLayer::create(lands);
playerLayer->setTag(LAYER_PLAYER);
addChild(playerLayer);
this->landsLayer = lands;
lands->retain();
this->playerLayer = playerLayer;
playerLayer->retain();
return true;
}
示例9: found
bool LevelReader::readBackgroundLayers(XMLElement* _property, LevelData& data) const
{
// we've found the property "backgroundlayers"
const char* textAttr = nullptr;
textAttr = _property->Attribute("value");
if (textAttr == nullptr)
{
g_logger->logError("LevelReader", "XML file could not be read, no value attribute found (map->properties->property->name=backgroundlayer).");
return false;
}
std::string backgroundLayerText = textAttr;
size_t pos = 0;
float distance = 0.f;
std::string backgroundLayer = "";
while ((pos = backgroundLayerText.find(",")) != std::string::npos)
{
distance = static_cast<float>(atof(backgroundLayerText.substr(0, pos).c_str()));
backgroundLayerText.erase(0, pos + 1);
if ((pos = backgroundLayerText.find(",")) != std::string::npos)
{
backgroundLayer = backgroundLayerText.substr(0, pos);
backgroundLayerText.erase(0, pos + 1);
}
else
{
backgroundLayer = backgroundLayerText;
backgroundLayerText.clear();
}
BackgroundLayer layer;
layer.load(backgroundLayer, distance);
data.backgroundLayers.push_back(layer);
}
return true;
}
示例10: getWindowWidth
void CristalWaveApp::setup()
{
float sizeW = getWindowWidth() * 0.5f;
float sizeH = getWindowHeight() * 0.5f;
float x = 0.0f,
z = 0.0f,
y = 0.0f;
/////////////////////////////////////////////////
int numRows = PARAM_WAVE_NB_ROWS;
int gap = PARAM_WAVE_GAP + getWindowWidth() / 2000;
int numLines = getWindowWidth() / gap + 1;
/////////////////////////////////////////////////
mOpacity = 0.0f;
mOffsetCameratH = 60; // Global amplitude
// Init BackgroundLayer
mBackground.setup(getWindowWidth(), getWindowHeight(), mOffsetCameratH);
// Init Wave Model
mWave.setup(getWindowWidth(), getWindowHeight(), numRows, numLines, -mOffsetCameratH);
// set a random offset
Rand rnd;
rnd.seed((unsigned long)GetTickCount());
mOffsetTime = rnd.nextFloat(0.0f, 100.0f);
// Set the Shader program
mFresnelShader.load();
mpWaveShader = &mFresnelShader;
mWave.setShader(mpWaveShader);
// --------------------------------------------------------
// Set Particule manager
int nbParticule = PARAM_NB_PARTICULES;
mEmitter.radius = PARAM_EMITTER_RADIUS;
mParticuleInTheWindManager.attrPosition = Vec3f::zero();
mParticuleInTheWindManager.attrFactor = PARAM_FORCE_FACTOR;
ParticuleManager::PARTICULE_LIFE particule_life;
particule_life.minTTL = 0.5f;
particule_life.maxTTL = 3.5f;
particule_life.minTTH = 1.0f;
particule_life.minTTH = 4.0f;
mParticuleInTheWindManager.init(nbParticule, particule_life, getWindowWidth());
}
示例11: fillUnsetProperties
void BackgroundLayer::fillUnsetProperties()
{
BackgroundLayer* curr;
for (curr = this; curr && curr->isBackgroundImageSet(); curr = curr->next());
if (curr && curr != this) {
// We need to fill in the remaining values with the pattern specified.
for (BackgroundLayer* pattern = this; curr; curr = curr->next()) {
curr->m_image = pattern->m_image;
pattern = pattern->next();
if (pattern == curr || !pattern)
pattern = this;
}
}
for (curr = this; curr && curr->isBackgroundXPositionSet(); curr = curr->next());
if (curr && curr != this) {
// We need to fill in the remaining values with the pattern specified.
for (BackgroundLayer* pattern = this; curr; curr = curr->next()) {
curr->m_xPosition = pattern->m_xPosition;
pattern = pattern->next();
if (pattern == curr || !pattern)
pattern = this;
}
}
for (curr = this; curr && curr->isBackgroundYPositionSet(); curr = curr->next());
if (curr && curr != this) {
// We need to fill in the remaining values with the pattern specified.
for (BackgroundLayer* pattern = this; curr; curr = curr->next()) {
curr->m_yPosition = pattern->m_yPosition;
pattern = pattern->next();
if (pattern == curr || !pattern)
pattern = this;
}
}
for (curr = this; curr && curr->isBackgroundAttachmentSet(); curr = curr->next());
if (curr && curr != this) {
// We need to fill in the remaining values with the pattern specified.
for (BackgroundLayer* pattern = this; curr; curr = curr->next()) {
curr->m_bgAttachment = pattern->m_bgAttachment;
pattern = pattern->next();
if (pattern == curr || !pattern)
pattern = this;
}
}
for (curr = this; curr && curr->isBackgroundClipSet(); curr = curr->next());
if (curr && curr != this) {
// We need to fill in the remaining values with the pattern specified.
for (BackgroundLayer* pattern = this; curr; curr = curr->next()) {
curr->m_bgClip = pattern->m_bgClip;
pattern = pattern->next();
if (pattern == curr || !pattern)
pattern = this;
}
}
for (curr = this; curr && curr->isBackgroundOriginSet(); curr = curr->next());
if (curr && curr != this) {
// We need to fill in the remaining values with the pattern specified.
for (BackgroundLayer* pattern = this; curr; curr = curr->next()) {
curr->m_bgOrigin = pattern->m_bgOrigin;
pattern = pattern->next();
if (pattern == curr || !pattern)
pattern = this;
}
}
for (curr = this; curr && curr->isBackgroundRepeatSet(); curr = curr->next());
if (curr && curr != this) {
// We need to fill in the remaining values with the pattern specified.
for (BackgroundLayer* pattern = this; curr; curr = curr->next()) {
curr->m_bgRepeat = pattern->m_bgRepeat;
pattern = pattern->next();
if (pattern == curr || !pattern)
pattern = this;
}
}
for (curr = this; curr && curr->isBackgroundSizeSet(); curr = curr->next());
if (curr && curr != this) {
// We need to fill in the remaining values with the pattern specified.
for (BackgroundLayer* pattern = this; curr; curr = curr->next()) {
curr->m_backgroundSize = pattern->m_backgroundSize;
pattern = pattern->next();
if (pattern == curr || !pattern)
pattern = this;
}
}
}
示例12:
void MainGameLayer3::addBackground()
{
BackgroundLayer* bgLayer = BackgroundLayer::create();
addChild(bgLayer, 0, kTagBackground);
bgLayer->incrementBlue(3);
}
示例13: addLifeCount
void BuyLifeLayer::addLifeCount(int count)
{
BackgroundLayer* layer = (BackgroundLayer*)GameScene::sharedGameScene()->getBackgroundLayer();
layer->addLifeCount(count);
}
示例14: fprintf
//.........这里部分代码省略.........
unsigned int rmask = 0x000000ff;
unsigned int gmask = 0x0000ff00;
unsigned int bmask = 0x00ff0000;
unsigned int amask = 0xff000000;
#endif
this->textSurface = SDL_CreateRGBSurface( 0, Renderer::screenWidth, Renderer::screenHeight, 32, rmask, gmask, bmask, amask);
OGLRenderableFactory factory = OGLRenderableFactory();
this->game = GameFactory::loadGame("game.xml");
this->game->loadCurrentLevel(&factory);
bExit = false;
soundManager = new SoundManager();
soundManager->init();
//soundManager->loadMusic("A991Project.ogg");
//soundManager->playCurrentMusic();
//soundManager->loadExplosionSound("Grenade-SoundBible.com-1777900486.wav");
particleManager = new ParticleManager();
/*
drawthread = SDL_CreateThread(thread_func, this);
if ( drawthread == NULL ) {
fprintf(stderr, "Unable to create draw thread: %s\n", SDL_GetError());
exit(0);
}
*/
this->game->setOnDestroyCallback(onDestroyCallback,this);
this->game->setOnHitCallback(onHitCallback,this);
this->fbAccumulation = NULL;
this->fbDrawing = NULL;
this->fbHalfRes1 = NULL;
this->fbHalfRes2 = NULL;
shaderTexturing = new Shader();
shaderTexturing->load_fragment("fragment_texturing.gl");
shaderTexturing->load_vertex("test.gl");
shaderDistort = new Shader();
shaderDistort->load_fragment("fragment_distort.gl");
shaderDistort->load_vertex("test.gl");
shaderGaussianBlurVertical = new Shader();
shaderGaussianBlurVertical->load_fragment("fragment_gaussian_vertical.gl");
shaderGaussianBlurVertical->load_vertex("test02.gl");
shaderGaussianBlurHorizontal = new Shader();
shaderGaussianBlurHorizontal->load_fragment("fragment_gaussian_horizontal.gl");
shaderGaussianBlurHorizontal->load_vertex("test02.gl");
Texture * texture = new Texture(2,2,(unsigned char*)g_texdata);
unsigned int * pixels = (unsigned int *)malloc(sizeof(unsigned int)*30*30);
TextureGenerator::generateTriangle(10,4,pixels,30,0xffffffff);
this->spriteAccumulation = new Sprite(texture,100.f,100.f,0,0,1,1);
this->spriteBullet = new Sprite(texture,5.f,5.f,1,1,0,0);
this->spriteDrawing = new Sprite(texture,100.f,100.f,0,0,1,1);
this->spriteDummy = new Sprite(texture,100.f,100.f,0,0,1,1);
this->spriteCovering = new Sprite(texture,Renderer::screenWidth,Renderer::screenHeight,0,0,1,1);
this->spriteRectangle = new Sprite(texture,10.f,1.f,0,0,1,1);
unsigned int * pixels2 = (unsigned int *)malloc(sizeof(unsigned int)*30*30);
TextureGenerator::generateCircle(0,0,pixels2,30,0xffffffff);
this->spriteCircle = new Sprite(new Texture(30,30,(unsigned char*)pixels2),10.f,10.f,1,1,0,0);
//this->spriteCircle = this->spriteBullet;
Texture * textSurfaceTexture = new Texture(Renderer::screenWidth,Renderer::screenHeight,(unsigned char*)this->textSurface->pixels);
this->spriteTextSurface = new Sprite(textSurfaceTexture,Renderer::screenWidth,Renderer::screenHeight,0,1,1,0);
this->spriteShip = new Sprite(new Texture(30,30,(unsigned char*)pixels),30.f,30.f,1,1,0,0);
unsigned int * pixelsgrid = (unsigned int*)malloc(sizeof(unsigned int)* 100 * 100);
TextureGenerator::generateGrid(pixelsgrid,100,100,20,0xff0909aa);
this->spriteGrid = new Sprite(new Texture(100,100,(unsigned char*)pixelsgrid),100.f,100.f,0,0,1,1);
BackgroundLayer * backgroundLayer = new BackgroundLayer(Renderer::screenWidth,Renderer::screenHeight);
backgroundLayer->addElement(this->spriteGrid,100,100);
this->backgroundManager.addLayer(backgroundLayer);
unsigned int * pixelsStarfield = (unsigned int*)calloc(sizeof(unsigned int), 100 * 100);
TextureGenerator::generateStarfield(pixelsStarfield,100,100,10);
backgroundLayer = new BackgroundLayer(Renderer::screenWidth,Renderer::screenHeight,0.0,-1.5f);
backgroundLayer->addElement(new Sprite(new Texture(100,100,(unsigned char*)pixelsStarfield),100.f,100.f,0,0,1,1),100,100);
this->backgroundManager.addLayer(backgroundLayer);
unsigned int * pixelsStarfield2 = (unsigned int*)calloc(sizeof(unsigned int), 100 * 100);
TextureGenerator::generateStarfield(pixelsStarfield2,100,100,10);
backgroundLayer = new BackgroundLayer(Renderer::screenWidth,Renderer::screenHeight,0.0,-1.0f);
backgroundLayer->addElement(new Sprite(new Texture(100,100,(unsigned char*)pixelsStarfield2),100.f,100.f,0,0,1,1),100,100);
this->backgroundManager.addLayer(backgroundLayer);
}
示例15: draw
void CristalWaveApp::draw()
{
//glClear(GL_COLOR_BUFFER_BIT); // A virer
// --------------------------------------------------------
// Set Camera for background
setCameraOrtho(Vec3f(0, 0, 500.0f));
gl::setMatrices(mCamera);
// Draw Background
mBackground.draw();
// --------------------------------------------------------
// Set Camera for wave
//setCameraOrtho(Vec3f(0, 140, 1000.0f));
setCameraOrtho(Vec3f(0, mCameraAltitude, 1000.0f));
gl::setMatrices(mCamera);
// --------------------------------------------------------
// Draw Wave
mWave.draw();
// --------------------------------------------------------
// Draw particules
mParticuleInTheWindManager.drawBatch();
// --------------------------------------------------------
// Fade in effect
fadeLayer(1.0f - mOpacity);
}