Check the Code:
Void physicsfixedupdate: onenter ()
{
Physicsdemo: onenter ();
_ Scene-> getphysicsworld ()-> setdebugdrawmask (physicsworld: debugdraw_all );
_ Scene-> getphysicsworld ()-> setgravity (point: zero );
// Wall
Auto wall = node: Create ();
Wall-> setphysicsbody (physicsbody: createedgebox (visiblerect: getvisiblerect (). Size, physicsmaterial (0.1f, 1, 0.0f )));
Wall-> setposition (visiblerect: Center ());
This-> addchild (Wall );
Addball ();
Scheduleonce (schedule_selector (physicsfixedupdate: updatestart), 2 );
}
Void physicsfixedupdate: addball ()
{
Auto ball = sprite: Create ("images/ball.png ");
Ball-& gt; setposition (100,100 );
Ball-> setphysicsbody (physicsbody: createcircle (ball-> getcontentsize (). width/2, physicsmaterial (0.1f, 1, 0.0f )));
Ball-> getphysicsbody ()-> settag (drag_bodys_tag );
Ball-> getphysicsbody ()-> setvelocity (point ));
This-> addchild (ball );
}
Void physicsfixedupdate: updatestart (float delta)
{
Addball ();
// The focus is here
_ Scene-> getphysicsworld ()-> setautostep (false );
Scheduleupdate ();
}
Void physicsfixedupdate: Update (float delta)
{
// Use fixed time and calculate 3 times per frame makes physics simulate more precisely.
// Here, it indicates that the first step is 3. If the FPS is 1/60, the third setp is 1/180.
For (INT I = 0; I <3; ++ I)
{
_ Scene-> getphysicsworld ()-> step (1/180. 0f );
}
}
Cocos2d-x3.3 physics physical engine module solves the problem of Rigid Body penetration