Хорошо, я следовал руководству Рэя и нашел решение ошибки parallaxNode.
ОБНОВЛЕНО ДЛЯ ВЕРСИИ COCOS2DX-3.X
В ParallaxNodeExtras.h сделайте следующее:
#include "cocos2d.h"
USING_NS_CC;
class ParallaxNodeExtras : public ParallaxNode {
public :
static ParallaxNodeExtras* create();
void updatePosition();
} ;
Теперь переключитесь на ParallaxNodeExtras.cpp и сделайте следующее.
#include "ParallaxNodeExtras.h"
class PointObject : public Ref
{
public:
inline void setRation(Point ratio) {_ratio = ratio;}
inline void setOffset(Point offset) {_offset = offset;}
inline void setChild(Node *var) {_child = var;}
inline Point getOffset() const {return _offset;}
inline Node* getChild() const {return _child;}
private:
Point _ratio;
Point _offset;
Node* _child;
};
ParallaxNodeExtras* ParallaxNodeExtras::create()
{
// Create an instance of InfiniteParallaxNode
ParallaxNodeExtras* node = new ParallaxNodeExtras();
if(node) {
// Add it to autorelease pool
node->autorelease();
} else {
// Otherwise delete
delete node;
node = 0;
}
return node;
}
void ParallaxNodeExtras::updatePosition()
{
int safeOffset = -10;
// Get visible size
Size visibleSize = Director::getInstance()->getVisibleSize();
// 1. For each child of an parallax node
for(int i = 0; i < _children.size(); i++)
{
auto node = _children.at(i);
// 2. We check whether it is out of the left side of the visible area
auto offsetx = convertToWorldSpace(node->getPosition()).x;
auto offsetw = node->getContentSize().width;
int offsetxw = offsetx + offsetw;
if(offsetxw < safeOffset)
// 3. Find PointObject that corresponds to current node
for(int i = 0; i < _parallaxArray->num; i++)
{
auto po = (PointObject*)_parallaxArray->arr[i];
// If yes increase its current offset on the value of visible width
if(po->getChild() == node)
po->setOffset(po->getOffset() +
Point(visibleSize.width + node->getContentSize().width,0));
}
}
}
Теперь в "HelloWorldScene.cpp" или в вашей GAME_SCENE замените
//Create the CCParallaxNode
_backgroundNode = ParallaxNodeExtras::node();
со следующей строкой
//Create the CCParallaxNode
_backgroundNode = ParallaxNodeExtras::create();
и следующая строка в функции обновления
_backgroundNode->incrementOffset(Vec2(2000,0),background);
с этой строкой
_backgroundNode->updatePosition();
P.S. Некоторым из вас может потребоваться настроить значения смещения.
Удачного кодирования! Пожалуйста, проголосуйте, если это решит вашу проблему :)
person
LeoSarena
schedule
12.10.2014
CCParallaxNodeExtras::CCParallaxNodeExtras() { }
, он может вызвать эту ошибку - person SBKarr   schedule 28.03.2014