@SonarSystems
Oh yes… here is my all code for understanding. Note: the values carefully so that you would be able to explain me better.
Now, I am able to achieve what I wanted in the NOWs code I would like you to focus on BEFORE code of s2 and compare it with other code.
Here is the code to give you better picture:
For s1
BEOFRE: // This below code was setting the s1Body a little shifted to left and below of the sprite s1 So I had to change anchor Point of s1(see NOW code of s1)
And also the position of the s1 is according to s1->setPosition(Point(visibleSize.width/2, visibleSize.height/3));
auto s1= Sprite::create("s1.png");
s1->setPosition(Point(visibleSize.width/2, visibleSize.height/3));
s1->setScale(0.5);
//NOTE: by deafult anchor is set to 0.5,0.5, so no need to change it … NO PROBLEM NOW FOR s1
MyBodyParser::getInstance()->parseJsonFile(“s1.json”);
auto s1Body = MyBodyParser::getInstance()->bodyFormJson(s1,“Name”,PhysicsMaterial(10,0.2,1));
s1->setPhysicsBody(s1Body);
NOW: // Exactly what I wanted . NO PROBLEM WITH THIS CODE
auto s1= Sprite::create("s1.png");
// Dividing it by 8 is weird by it actually helped
s1->setPosition(Point(visibleSize.width/2-s1->getContentSize().width/8, visibleSize.height/3));
s1->setScale(0.5);
s1->setAnchorPoint(Vec2(0.25,0.25));
s1->setContentSize(Size(s1->getContentSize().width/2,s1->getContentSize().height/2));
MyBodyParser::getInstance()->parseJsonFile("s1.json");
auto s1Body = MyBodyParser::getInstance()->bodyFormJson(s1,"Name",PhysicsMaterial(10,0.2,1));
s1->setPhysicsBody(s1Body);
For s2
BEFORE: //This code is placing s2Body a shifted from the center of s2 and nothing is happening even if I change setAnchor to anything
// I WANT TO MAKE THIS WORK THE WAY IT WORKED FOR s1
auto s2= Sprite::create("s2.png");
s2->setPosition(Point(visibleSize.width/2, 3*visibleSize.height/4));
s2->setScale(0.5);
// s2->setAnchorPoint(Vec2(5,5)); // Uncomment and set it to Anything and it won’t change even a single thing on my screen
s2->setContentSize(Size(s2->getContentSize().width/2,s2->getContentSize().height/2));
// NOTE: I am dividing by 2 because it is radius and although I’ve set scale of s2 to half but I’ve set mycontentSize to half too.
// So, overall effect is that it is giving me a circle of same size as of scaled down s1.
auto s2Body= PhysicsBody::createCircle(s2->getContentSize().width/2,PhysicsMaterial(0,1,0));
s2->setPhysicsBody(s2Body);
NOW: //Natural way of setting a physics body and it worked to exactly what I want
auto s2= Sprite::create("s2.png");
s2->setPosition(Point(visibleSize.width/2, 3*visibleSize.height/4));
s2->setScale(0.5);
//Be deafault achor for s2 is 0.5,0.5 so no need to change
// I am dividing by 4 because it is radius and also I’ve already reduced the s2 scale to 0.5
auto s2Body= PhysicsBody::createCircle(s2->getContentSize().width/4,PhysicsMaterial(0,1,0));
s2->setPhysicsBody(s2Body);
NOTE: In BEFORE CODE OF s2 The position of s2Body is appearing according to
s2->setPosition(Point(visibleSize.width/2, 3*visibleSize.height/4)); but the actual sprite s2 is little shifted to right and above And settingAnchoring is not letting change anything. I think setAnchor is working for s1 but not s2 LOL
Thanks again…