How to delete object after addchild?

auto item = Sprite::create("item.png");
	item->setPosition(Vec2(500,300));
	item->setScale(0.1);
	addChild(item, 100);
	auto itembody = PhysicsBody::createBox(Size(item->getContentSize().width / 2, item->getContentSize().height / 1.5));
	
item->setPhysicsBody(itembody);
	itembody->setDynamic(false);
	itembody->setGravityEnable(false);
	itembody->setCollisionBitmask(55);
	itembody->setContactTestBitmask(true);

How can I delete it and its properties from the screen.

something like this?

removeChild(item);
itembody->removeFromWorld();
removeChild("TheAsset");

Though this just removes it from the screen. It’s data isn’t exterminated.

1 Like

There isn’t a syntax in the framework with goes by the name of removeFromWorld();

:slight_smile:

??

CCPhysicsBody.cpp line 731

void PhysicsBody::removeFromWorld()
{
    removeFromPhysicsWorld();
}
1 Like

Terribly sorry, I must’ve not had the correct “#include XYZ”