0
您好,我正在瀏覽Raywenderlich的教程(http://www.raywenderlich.com/33752/),使用Eclipse for Android平臺在Cocos2d-x-2.2中創建Space Game。Raywenderlich教程 - 太空遊戲
我在「添加視差滾動」部分出現了問題。複製粘貼代碼後,我無法看到背景精靈。
.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);
任何想法在哪裏可以在我執行錯誤?資源被正確添加,因爲正在顯示船隻。
你似乎沒有任何渲染代碼 –
你能告訴我更多一點嗎?或者告訴我它在教程中的位置? – F1sher