quick-cocos2d-x3.3 Study (12)---------Create a rounded object with a physical engine effect

Source: Internet
Author: User

Create a heart-to-heart picture with physical effects

Create a physical scene first

1Local Gamescene =class("Gamescene", function ()2--Body3--returnDisplay.newscene ("Gamescene")4--create a scene with a physical effect5     returnDisplay.newphysicsscene ("Gamescene")6End

Add physical heart to this physical world

1--Gets the physical world object bound in the scene2Self.world =Self:getphysicsworld ();3--set the acceleration of gravity in a scene4Self.world:setGravity (CC.P (0, -98.0 ) ) ;5--set debug state where physical effects can be seen6 Self.world:setDebugDrawMask (CC. Physicsworld.debugdraw_all);7 8 9--Create a heart and heart with physical effectsTenSelf.heart = Display.newsprite ("Image/pic/heart.png") One--set the location of the heart ASelf.heart:setPosition (display.cx, Display.top-self.heart:getContentSize (). Height) ---add hearts to the scene - self.heart:addTo (self) the  ---Set the density, bounce force, and friction of the object, ---Set it all to0to make no physical changes in the event of a collision. -Local material_default = cc. Physicsmaterial (0.0,0.0,0.0 ) +--1 -Local Heartbody =cc. Physicsbody:createcircle ( +Self.heart:getContentSize (). Width/2, Material_default A     ) at--adding a physical engine to an object - self.heart:setPhysicsBody (heartbody) ---shielding the body of the physical world from the effects of gravity ---Self.heart:getPhysicsBody (): Setgravityenable (false)

Here the cc.PhysicsBody::createCircle() method is called to create a circle body;

Createcircle (RADIUS, material, offset),

The Createcircle method has three parameters, namely:

    • The parameter 1 is the Cc.size type, which represents the outer radius of the circle body.
    • The parameter 2 is CC. The physicsmaterial type, which represents the properties of the physical material,
      • CC is the default. Physicsbody_material_default.
        • This parameter can also be customized, as follows:
          cc.PhysicsMaterial(density, restitution, friction)
        • Density: Indicates density
        • Restitution: Indicates a rebound force
        • Friction: Indicates friction
    • The parameter 3 is the CC.P type, and it is an optional parameter that represents the offset of the body from the center point, which is CC.P (0,0) by default.

The 26th line, after the comment

Non-annotated

quick-cocos2d-x3.3 Study (12)---------Create a rounded object with a physical engine effect

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.