@pococogames @ricardo
Thanks for the clarification on anchor points.
Can we have a custom function(function overloading) which takes additional parameters for x and y where each valuse ranges from 0-1. Based on this, we can decide where on anchor point we want to place the child!.
Eg. If I do, parentSprite->addChild(childSprite, 0.5,0.5) then it will add the child in the center of the parent Sprite.
If I add a sprite to a node object just like that;
auto mySprite=Sprite::create("sampleSpriten.png");
myNode->addChild(mySprite);
I donāt have any problem. Because the sprite object anchor point was in the center.(Default anchor point 0.5 and 0.5) Iām adding this sprite to a node object, zero point is always at center of sprite in the node object. But I canāt do that with when I add a child sprite object to a parent sprite object.
For example;
auto parentSprite=Sprite::create("parentImage.png");
auto childSprite=Sprite::create("childImage.png");
parentSprite->addChild(childSprite);
If I use that, child sprite is always add at bottom left of the parentSprite. But the child sprite and the parent sprite anchor point values are already (0.5,0.5). And I canāt think that is logical.
Note: I have solved my own problem with that way. (Itās like a joke )
I prefer not overload addChild, but you can add a free function that does that.
eg:
// might not compile... treat it as pseudo code
void addChild(Node* parent, Node* child, const Vec2& anchorPoint)
{
auto s = parent->getSize();
parent->addChild(child);
child->setPosition(s * anchorPoint); // you can't multiply Vec2 with Size, but you get the idea
}
yes, we should say that anchorPoint only affects the transform operations (scale, position, rotate, skew, etcā¦) and does not affect children positioning. In fact, children will be always added to the bottom-left (0,0) corner of its parent
Hi pocoā¦
Itās not a problem. Itās just the design which looks not normal and also I think less people would be knowing about it. @slackmoehrle Can you please mention this in programmerās guide if it is of significance.
@pococogames
If you feel, like me, that it should position in the center, then following things can be done:
1) Make a helper function in our code that will have this functionality and will automatically position the child according to our wish. Something like customaddChild() in our own sprite classā¦ Note, you would have to extend this class from Sprite(obviously)
2) Or else you can directly add custom function inside Sprite class of the cocos2d-x library itself, build the library(if youāre using prebuild library).
3) If you think this above 2nd point is of significance and it should be present in the Node/Sprite class by default then discuss with ricardo/slackmoehrl/ @zhangxm and pull request to git can be sent.
Yes, it may/may not be. But as ricardo told, it is probably not the mistake but choice for designā¦
So, the best thing cocos2dx offers is that it is open sourceā¦ so you can edit the functionality any timeā¦ like 2nd step, I told is the best pick in case you feel intrigued by implementing helper functionā¦
PhysicsBody *pb=PhysicsBody::createBox(Size(15,5),PhysicsMaterial(0.1f,0.0f,1.0f));
this->addComponent(pb);
this->removeComponent(pb); // I get EXC_BAD_ACCESS error
Yep. I get the same error. I tried. Iām using this way in my project for now;
this->getPhysicsBody->setEnabled(false);
Itās not problem for me , because this object will be removed next time in the scene. But If I canāt remove any object in my project, I need remove PhysicsBody component from the node object. (Imagine, maybe I need more performance optimization )
@pococogames
Itās strange looking at your issueā¦
Iāll try our your code, probably day after tomorrow(sorry travelling somewhere, so taking time).
Meanwhile, please put your code to github or somewhere bcoz as @ricardo told your codeās link is expired.
Iāve done physics body removal in my prototype in v3.3. In case anything going wrong, Iāll cross check.