Hi,
I want to ask which one/both is correct way.
QUESTION (Check the statement in below code)
Creation of sprite is synchronous task(AFAIK) but just wanted to confirm it.
In other words, will it popUp Sprite be already created before executing this statement or the 2nd approach is safer?
I know separating it into multiple functions doesn’t make difference but my questions arises mainly if this->Child(popUp, 1)
this could make a difference.
Eg- in 1st case, s1 s2
are being added to SOME child of this
which has to exist while in 2nd case s1 s2
are being added to local popup sprite, creation of which is synchronous and which whenever gets added to this
as a child, I don’t have to care.
.
.
HelloWorld::init()
{
.
.
this->createPopUp(); // Some function to add a pop up Sprite in the current layer
// Pop up name is set as "popup" in createPopUp function
auto s1 = Sprite::create(...);
//Set s1 position
auto s1 = Sprite::create(...);
//Set s2 position
// ***QUESTION*** ???
this->getChildByName("popup")->addChild(s1, 1);
this->getChildByName("popup")->addChild(s2, 1);
.
.
}
OR
.
.
HelloWorld::init() {
.
.
this->createPopUp(); // Some function to add a pop up Sprite in the current layer
// Pop up name is set as "popup" in createPopUp function
.
.
}
void HelloWorld::createPopUp()
{
auto popupSprite = Sprite::create(...);
//set popupSprite position
popupSprite->SetName("popup");
this->addChild(popupSprite, 1);
auto s1 = Sprite::create(...);
//Set s1 position
auto s1 = Sprite::create(...);
//Set s2 position
popupSprite->addChild(s1, 1 );
popupSprite->addChild(s2, 1 );
}