您好我正在使用Raymanderlich的教程(http://www.raywenderlich.com/33752/)使用Eclipse for Android平台在Cocos2d-x-2.2中创建Space Game。
我在“添加视差滚动”部分出现了问题。复制粘贴代码后,我看不到背景精灵。
.cpp文件
bool HelloWorld::init()
{
if ( !CCLayer::init() )
{
return false;
}
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
/////////////////////////////
_batchNode = CCSpriteBatchNode::create("Sprites.pvr.ccz");
this->addChild(_batchNode);
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Sprites.plist");
_ship = CCSprite::createWithSpriteFrameName("SpaceFlier_sm_1.png");
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
_ship->setPosition(ccp(winSize.width * 0.1, winSize.height * 0.5));
_batchNode->addChild(_ship, 1);
return true;
// 1) Create the CCParallaxNode
_backgroundNode = CCParallaxNode::create();
this->addChild(_backgroundNode,-1);
// 2) Create the sprites will be added to the CCParallaxNode
_spacedust1 = CCSprite::create("bg_front_spacedust.png");
_spacedust2 = CCSprite::create("bg_front_spacedust.png");
_planetsunrise = CCSprite::create("bg_planetsunrise.png");
_galaxy = CCSprite::create("bg_galaxy.png");
_spacialanomaly = CCSprite::create("bg_spacialanomaly.png");
_spacialanomaly2 = CCSprite::create("bg_spacialanomaly2.png");
// 3) Determine relative movement speeds for space dust and background
CCPoint dustSpeed = ccp(0.1, 0.1);
CCPoint bgSpeed = ccp(0.05, 0.05);
// 4) Add children to CCParallaxNode
_backgroundNode->addChild(_spacedust1, 0, dustSpeed, ccp(0,winSize.height/2) );
_backgroundNode->addChild(_spacedust2, 0, dustSpeed, ccp( _spacedust1->getContentSize().width,winSize.height/2));
_backgroundNode->addChild(_galaxy, -1, bgSpeed, ccp(0, winSize.height * 0.7));
_backgroundNode->addChild(_planetsunrise, -1 , bgSpeed, ccp(600, winSize.height * 0));
_backgroundNode->addChild(_spacialanomaly, -1, bgSpeed, ccp(900, winSize.height * 0.3));
_backgroundNode->addChild(_spacialanomaly2, -1, bgSpeed, ccp(1500, winSize.height * 0.9));
this->scheduleUpdate();
}
void HelloWorld::update(float dt) {
CCPoint backgroundScrollVert = ccp(-1000, 0);
_backgroundNode->setPosition(ccpAdd(_backgroundNode->getPosition(), ccpMult(backgroundScrollVert, dt)));
}
.h文件
class HelloWorld : public cocos2d::CCLayer
{
private:
cocos2d::CCSpriteBatchNode * _batchNode;
cocos2d::CCSprite * _ship;
cocos2d::CCParallaxNode *_backgroundNode;
cocos2d::CCSprite *_spacedust1;
cocos2d::CCSprite *_spacedust2;
cocos2d::CCSprite *_planetsunrise;
cocos2d::CCSprite *_galaxy;
cocos2d::CCSprite *_spacialanomaly;
cocos2d::CCSprite *_spacialanomaly2;
// scheduled Update
void update(float dt);
任何想法可能是我的实施中的错误?由于正在展示船舶,因此正在增加资源。
答案 0 :(得分:0)
有:
return true;
在代码中间。