Skip to content

Instantly share code, notes, and snippets.

Created February 20, 2014 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/9115091 to your computer and use it in GitHub Desktop.
Save anonymous/9115091 to your computer and use it in GitHub Desktop.
//init
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
// Creating the CCParallaxNode
_backgroundNode = CCParallaxNode::create();
this->addChild(_backgroundNode, -1);
_spacebg1 = CCSprite::create("mm-gfx/bg-mm.png");
_spacebg2 = CCSprite::create("mm-gfx/bg-mm.png");
CCPoint dustSpeed = ccp(0.1, 0.1);
CCPoint bgSpeed = ccp(0.05, 0.05);
_backgroundNode->addChild(_spacebg1, 0, dustSpeed, ccp(winSize.width / 2, winSize.height / 2));
_backgroundNode->addChild(_spacebg2, 0, dustSpeed, ccp(_spacebg1->getContentSize().width, winSize.height / 2));
this->scheduleUpdate();
//...
//update/tick function
void MainMenuLayer::update(float dt) {
CCPoint backgroundScrollVert = ccp(-100, 0);
_backgroundNode->setPosition(ccpAdd(_backgroundNode->getPosition(), ccpMult(backgroundScrollVert, dt)));
}
#ifndef __MAINMENU_SCENE_H__
#define __MAINMENU_SCENE_H__
#include "cocos2d.h"
USING_NS_CC;
class MainMenuLayer : public cocos2d::CCLayer
{
private:
CCParallaxNode *_backgroundNode;
CCSprite* _spacebg1;
CCSprite* _spacebg2;
void update(float dt);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment