-
hamletLikes 0Problem Description
Hello one more time i have ussue with my layer in cocos2d-x , i need to make a inheritance in my class Helloworld with my class Pulsaciones.
class HelloWorld : public cocos2d::Layer ,public Pulsaciones
{
public:
static cocos2d::Scene* createScene();
virtual bool init();
// a selector callback
// implement the "static create()" method manually
CREATE_FUNC(HelloWorld);
cocos2d::Size visibleSize;
cocos2d::Vec2 origin;
void Button1(Ref *pSender);
void Button2(Ref *pSender);
void Button3(Ref *pSender);
void Button4(Ref *pSender);
void Button5(Ref *pSender);
void Button6(Ref *pSender);
Vec2 Coding();
// called when the user moves their finger
private:void Bodylayer(float dt);
void update( float dt );
Pulsaciones *pulsaciones;
};but i can not acces to the function of Pulsaciones when i make inside helloworld class Pulsaciones::getCode(int); for example(the cocos2d get Build successfull but the return of each variable in layer is data garbage in Helloworld while in Pulsaciones layer is good) how can i make good implementation of inheritance in cocos2d.
class Pulsaciones
{
public:int i;
Vec2 Charge;
Vec2 first,second,third,fourth,fifth,sixth;
Pulsaciones();
void Bodylayer(cocos2d::Layer *layer);
void Code();
Sprite *frontdisplay;
void setCode(Vec2,Vec2,Vec2,Vec2,Vec2,Vec2);
Vec2 getCode(int);
//std::vector<Sprite*>code;
cocos2d::Sprite *backgrounddisplay;
private:
cocos2d::Size visibleSize;
cocos2d::Vec2 origin;
bool isWrite;
Vec2 positions[6];
};
-
Sonar Systems adminLikes 0
Have you assigned values to the variables.
-
hamletLikes 0
yes to all
Pulsaciones::Pulsaciones(){
visibleSize = Director::getInstance( )->getVisibleSize( );
Vec2 origin = Director::getInstance( )->getVisibleOrigin( );
}
void Pulsaciones::Bodylayer(cocos2d::Layer *layer)
{
auto backgrounddisplay=Sprite::createWithSpriteFrameName("backgrounddisplay.png");
backgrounddisplay->setPosition(Vec2(visibleSize.width/2 +origin.x, visibleSize.height/2+origin.y));
layer->addChild(backgrounddisplay,-2);
auto frontdisplay=Sprite::createWithSpriteFrameName("frontdisplay.png");
frontdisplay->setPosition(Vec2(visibleSize.width/2 +origin.x, visibleSize.height/2+origin.y));
layer->addChild(frontdisplay);Vec2 first = Vec2(frontdisplay->getPositionX()- frontdisplay->getContentSize().width/-2.5,
frontdisplay->getPositionY()+frontdisplay->getContentSize().height/-26);Vec2 second = Vec2(frontdisplay->getPositionX()- frontdisplay->getContentSize().width/-4.1,
frontdisplay->getPositionY()+frontdisplay->getContentSize().height/-26);Vec2 third = Vec2(frontdisplay->getPositionX()- frontdisplay->getContentSize().width/-11.8,
frontdisplay->getPositionY()+frontdisplay->getContentSize().height/-26);Vec2 fourth = Vec2(frontdisplay->getPositionX()-frontdisplay->getContentSize().width/11.7,
frontdisplay->getPositionY()+ frontdisplay->getContentSize().height/-26);Vec2 fifth = Vec2(frontdisplay->getPositionX()-frontdisplay->getContentSize().width/4.1,
frontdisplay->getPositionY()+ frontdisplay->getContentSize().height/-26);
Vec2 sixth = Vec2(frontdisplay->getPositionX()-frontdisplay->getContentSize().width/2.5,
frontdisplay->getPositionY()+ frontdisplay->getContentSize().height/-26);//position variable control
int i;i=2;
Charge=getCode(i);
auto Signal1=Sprite::createWithSpriteFrameName("signal1.png");
Signal1->setPosition(getCode(i));
layer->addChild(Signal1,2);setCode(first,second,third,fourth,fifth,sixth);
}void Pulsaciones::setCode(Vec2 uno ,Vec2 dos ,Vec2 tres ,Vec2 cuatro ,Vec2 cinco,Vec2 seis)
{Vec2 *Uno;
Uno=&uno;
Vec2 *Dos;
Dos=&dos;
Vec2 *Tres;
Tres=&tres;
Vec2 *Cuatro;
Cuatro=&cuatro;
Vec2 *Cinco;
Cinco=&cinco;
Vec2 *Seis;
Seis=&seis;positions[0] = *Uno;
positions[1] = *Dos;
positions[2] = *Tres;
positions[3] = *Cuatro;
positions[4] = *Cinco;
positions[5] = *Seis;
}
Vec2 Pulsaciones::getCode(int counter){
int count;
count=counter-1;
if (count<0){
}
else if (count>=0 && count<=6){
return positions[count];
}else{
}
}and im pulsaciones the Sprite take the position very well
-
Sonar Systems adminLikes 0
Try a simple class to see if it successfully inherits it
-
hamletLikes 0
for my it is the inheritance that Helloworld with the layer in scope dont allow this , i need to find other way for make the Helloworld scene (Class HelloWorld : public cocos2d::Layer ,in this part not allow make inheritance with other class[i think])
-
Sonar Systems adminLikes 0
Try making the other class inherit Layer then your class inherits that class.
Login to reply