0
안녕하세요, 안드로이드 플랫폼 용 Eclipse를 사용하여 Cocos2d-x-2.2에서 우주 게임을 만들기 위해 Raywenderlich의 자습서 (http://www.raywenderlich.com/33752/)를 사용하고 있습니다.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