Cocos2d-x3.3 Physics physical engine module solves the problem of Rigid Body penetration, cocos2dx3.3

Source: Internet
Author: User

Cocos2d-x3.3 Physics physical engine module solves the problem of Rigid Body penetration, cocos2dx3.3

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 );

}

}


Simulated Driving 2011 cannot create physical engine physics engine instance cocould not be created

NVIDIA PhysX physical acceleration driver 9.10.0513 For WinXP/XP-64/Vista-64/Win7/Win7-64, updates include: fixed the issue of PhysX Acceleration not working properly on Optimus PC.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.