// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !CCLayerColor::initWithColor(ccc4(255, 255, 255, 255)) ) { return false; } CCSprite *pBackground = CCSprite::create("Images/background.png"); pBackground->setAnchorPoint(ccp(0, 0)); CCParallaxNode *pVoidNode = CCParallaxNode::create(); pVoidNode->addChild(pBackground, 1, ccp(1.0f, 0.0f), ccp(0, 0)); CCMoveBy *go = CCMoveBy::create(4, ccp(-160, 0)); CCActionInterval *goBack = go->reverse(); CCSequence *seq = CCSequence::create(go, goBack, NULL); CCAction *act = CCRepeatForever::create(seq); pVoidNode->runAction(act); this->addChild(pVoidNode); return true; }
//------------------------------------------------------------------ // // ParallaxParticle // //------------------------------------------------------------------ void ParallaxParticle::onEnter() { ParticleDemo::onEnter(); m_background->getParent()->removeChild(m_background, true); m_background = NULL; CCParallaxNode* p = CCParallaxNode::node(); addChild(p, 5); CCSprite *p1 = CCSprite::spriteWithFile(s_back3); CCSprite *p2 = CCSprite::spriteWithFile(s_back3); p->addChild( p1, 1, CGPointMake(0.5f,1), CGPointMake(0,250) ); p->addChild(p2, 2, CGPointMake(1.5f,1), CGPointMake(0,50) ); m_emitter = CCParticleFlower::node(); m_emitter->retain(); m_emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) ); p1->addChild(m_emitter, 10); m_emitter->setPosition( CGPointMake(250,200) ); CCParticleSun* par = CCParticleSun::node(); p2->addChild(par, 10); par->setTexture( CCTextureCache::sharedTextureCache()->addImage(s_fire) ); CCActionInterval* move = CCMoveBy::actionWithDuration(4, CGPointMake(300,0)); CCActionInterval* move_back = move->reverse(); CCFiniteTimeAction* seq = CCSequence::actions( move, move_back, NULL); p->runAction(CCRepeatForever::actionWithAction((CCActionInterval*)seq)); }
Parallax1::Parallax1() { // Top Layer, a simple image CCSprite* cocosImage = CCSprite::spriteWithFile(s_Power); // scale the image (optional) cocosImage->setScale( 2.5f ); // change the transform anchor point to 0,0 (optional) cocosImage->setAnchorPoint( ccp(0,0) ); // Middle layer: a Tile map atlas CCTileMapAtlas *tilemap = CCTileMapAtlas::tileMapAtlasWithTileFile(s_TilesPng, s_LevelMapTga, 16, 16); tilemap->releaseMap(); // change the transform anchor to 0,0 (optional) tilemap->setAnchorPoint( ccp(0, 0) ); // Anti Aliased images tilemap->getTexture()->setAntiAliasTexParameters(); // background layer: another image CCSprite* background = CCSprite::spriteWithFile(s_back); // scale the image (optional) background->setScale( 1.5f ); // change the transform anchor point (optional) background->setAnchorPoint( ccp(0,0) ); // create a void node, a parent node CCParallaxNode* voidNode = CCParallaxNode::node(); // NOW add the 3 layers to the 'void' node // background image is moved at a ratio of 0.4x, 0.5y voidNode->addChild(background, -1, ccp(0.4f,0.5f), CCPointZero); // tiles are moved at a ratio of 2.2x, 1.0y voidNode->addChild(tilemap, 1, ccp(2.2f,1.0f), ccp(0,-200) ); // top image is moved at a ratio of 3.0x, 2.5y voidNode->addChild(cocosImage, 2, ccp(3.0f,2.5f), ccp(200,800) ); // now create some actions that will move the 'void' node // and the children of the 'void' node will move at different // speed, thus, simulation the 3D environment CCActionInterval* goUp = CCMoveBy::actionWithDuration(4, ccp(0,-500) ); CCActionInterval* goDown = goUp->reverse(); CCActionInterval* go = CCMoveBy::actionWithDuration(8, ccp(-1000,0) ); CCActionInterval* goBack = go->reverse(); CCFiniteTimeAction* seq = CCSequence::actions(goUp, go, goDown, goBack, NULL); voidNode->runAction( (CCRepeatForever::actionWithAction((CCActionInterval*) seq) )); addChild( voidNode ); }
Parallax2::Parallax2() { setIsTouchEnabled( true ); // Top Layer, a simple image CCSprite* cocosImage = CCSprite::spriteWithFile(s_Power); // scale the image (optional) cocosImage->setScale( 2.5f ); // change the transform anchor point to 0,0 (optional) cocosImage->setAnchorPoint( ccp(0,0) ); // Middle layer: a Tile map atlas CCTileMapAtlas* tilemap = CCTileMapAtlas::tileMapAtlasWithTileFile(s_TilesPng, s_LevelMapTga, 16, 16); tilemap->releaseMap(); // change the transform anchor to 0,0 (optional) tilemap->setAnchorPoint( ccp(0, 0) ); // Anti Aliased images tilemap->getTexture()->setAntiAliasTexParameters(); // background layer: another image CCSprite* background = CCSprite::spriteWithFile(s_back); // scale the image (optional) background->setScale( 1.5f ); // change the transform anchor point (optional) background->setAnchorPoint( ccp(0,0) ); // create a void node, a parent node CCParallaxNode* voidNode = CCParallaxNode::node(); // NOW add the 3 layers to the 'void' node // background image is moved at a ratio of 0.4x, 0.5y voidNode->addChild(background, -1, ccp(0.4f,0.5f), CCPointZero); // tiles are moved at a ratio of 1.0, 1.0y voidNode->addChild(tilemap, 1, ccp(1.0f,1.0f), ccp(0,-200) ); // top image is moved at a ratio of 3.0x, 2.5y voidNode->addChild( cocosImage, 2, ccp(3.0f,2.5f), ccp(200,1000) ); addChild(voidNode, 0, kTagNode); }
bool GameLevelLayer::initWithLevel(int level) { bool bRet = CCLayer::init(); if( bRet == true) { this->currentLevel = level; char levelName[10]; CCDictionary *levelsDict = CCDictionary::createWithContentsOfFile("levels.plist"); memset(levelName, 0, sizeof(levelName) ); sprintf(levelName, "level%d", level); //当前地图关卡的背景数据// CCDictionary *lvlDict = (CCDictionary *) levelsDict->objectForKey(levelName); //背景音乐// const char* bgMusic = lvlDict->valueForKey("music")->getCString(); SimpleAudioEngine::sharedEngine()->playBackgroundMusic(bgMusic, true); SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(0.25f); CCParallaxNode *pNode = CCParallaxNode::create(); CCArray *backGroundArray = (CCArray *) lvlDict->objectForKey("background"); CCObject *group1 = NULL; CCObject *group2 = NULL; CCARRAY_FOREACH( backGroundArray, group1) { CCArray *nodeArray = (CCArray *)group1; CCARRAY_FOREACH(nodeArray, group2) { CCString* fileName = (CCString *)group2; CCSprite *bgNodeSprite = CCSprite::create(fileName->getCString()); bgNodeSprite->setAnchorPoint( ccp(0.0f, 0.0f) ); int index = nodeArray->indexOfObject(group2); float index2 = (float) backGroundArray->indexOfObject(group1) + 1.0f; float ratio = ( ( 4.0f - index2) / 8.0f); if(index2 == 4.0f) ratio = 0.0f; pNode->addChild(bgNodeSprite, index2 * -1, ccp(ratio, 0.6f), ccp(index * 2048, 30)); }
bool ParallaxBackground::init() { if (CCLayer::init()) { setTouchEnabled(true); CCSprite* pBackground = CCSprite::create(); pBackground->initWithFile("Background/-1.png"); pBackground->setPosition(VisibleRect::center()); CCSprite* pMiddleground = CCSprite::create(); pMiddleground->initWithFile("Background/1.png"); pMiddleground->setPosition(VisibleRect::center()); CCSprite* pForegraund = CCSprite::create(); pForegraund->initWithFile("Background/2.png"); pForegraund->setPosition(VisibleRect::center()); CCSprite* pStatic = CCSprite::create(); pStatic->initWithFile("Background/3.png"); pStatic->setPosition(VisibleRect::center()); CCParallaxNode* voidNode = CCParallaxNode::create(); voidNode->addChild(pBackground, -1, ccp(-1.3f, 1.3f), VisibleRect::center()); voidNode->addChild(pMiddleground, 1, ccp(-1.0f, 1.0f), VisibleRect::center()); voidNode->addChild(pForegraund, 2, ccp(0.1f, 0.5f), VisibleRect::center()); voidNode->addChild(pStatic, 3, ccp(0.0f, 0.0f), VisibleRect::center()); addChild(voidNode, 0, 0); return true; } return false; }
// on "init" you need to initialize your instance bool FC_Intro::init() { bool bRet = false; do { this->setTouchEnabled(true); ////////////////////////////////////////////////////////////////////////// // super init first ////////////////////////////////////////////////////////////////////////// CC_BREAK_IF(! CCLayerColor::initWithColor(ccc4(255,255,255,255))); s = CCDirector::sharedDirector()->getWinSize(); // m_nGameLevel = 0; // easy m_nGameLevel = CCUserDefault::sharedUserDefault()->getIntegerForKey("FC_GAME_LEVEL", 0); // 상단 타이틀 영역 CCSprite* pTitleBG = CCSprite::create("common/game/game_top_bg.png"); pTitleBG->setPosition(ccp(0, s.height)); pTitleBG->setAnchorPoint(ccp(0, 1.0f)); // addChild(pTitleBG, 3); // Title 그리기 char* szLang = LanguageUtil::getLanguageCode(); char szTitle[260]; sprintf(szTitle, "common/game/flipCard/game_title_%s.png", szLang); CCSprite* pTitle = CCSprite::create(szTitle); pTitle->setPosition(ccp(s.width/2, s.height - pTitleBG->getContentSize().height/2)); this->addChild(pTitle, 4); /* // 배경 이미지 그리기 CCSprite* pBG = CCSprite::create("game/main_bg.png"); pBG->setAnchorPoint(ccp(0, 0)); pBG->setPosition(ccp(0, 0)); this->addChild(pBG, 2); */ // Main BG CCSprite* pBack_base = CCSprite::createWithTexture(CCTextureCache::sharedTextureCache()->addImage("Main/main_bg_base.png")); pBack_base->setAnchorPoint(ccp(0,0)); this->addChild( pBack_base ); CCSprite* pBack = CCSprite::createWithTexture(CCTextureCache::sharedTextureCache()->addImage("Main/main_bg.png")); CCSprite* pBack1 = CCSprite::createWithTexture(CCTextureCache::sharedTextureCache()->addImage("Main/main_bg1.png")); CCSprite* pBack2 = CCSprite::createWithTexture(CCTextureCache::sharedTextureCache()->addImage("Main/main_bg2.png")); pBack->setAnchorPoint(ccp(0,0)); pBack1->setAnchorPoint(ccp(0,0)); pBack2->setAnchorPoint(ccp(0,0)); CCParallaxNode* voidNode = CCParallaxNode::create(); voidNode->addChild(pBack, 1, ccp(1.0f,0.0f), ccp(0,0)); voidNode->addChild(pBack1, 1, ccp(1.0f,0.0f), ccp(1874,0) ); voidNode->addChild(pBack2, 1, ccp(1.0f,0.0f), ccp(3748,0) ); CCActionInterval* go = CCMoveBy::create(200, ccp(-3748,0) ); CCActionInterval* goBack = go->reverse(); CCFiniteTimeAction* seq = CCSequence::create(go, goBack, NULL); CCAction* act = CCRepeatForever::create( (CCActionInterval*) seq); voidNode->runAction( act ); this->addChild( voidNode ); // Guide Image CCSprite* pIntro = CCSprite::create("game/flipCard/main_img_bg.png"); pIntro->setPosition(ccp(s.width/2, GUIDE_BG_MARGIN_B)); pIntro->setAnchorPoint(ccp(0.5f, 0)); this->addChild(pIntro, 3); // Guide Text char szGuide[260]; sprintf(szGuide, "common/game/flipCard/guide_text_%s.png", szLang); CCSprite* pGuide = CCSprite::create(szGuide); pGuide->setPosition(GUIDE_TEXT_XY); pGuide->setAnchorPoint(ccp(0, 0.5f)); this->addChild(pGuide, 3); // 난이도, 뒤로가기 버튼 표시 CreateMenu(); bRet = true; } while (0); return bRet; }