/** Remove a body from physics world. */ public virtual void RemoveBody(CCPhysicsBody body) { if (body.GetWorld() != this) { cp.AssertWarn("Physics Warnning: this body doesn't belong to this world"); return; } // destory the body's joints foreach (var joint in body._joints) { // set destroy param to false to keep the iterator available RemoveJoint(joint, false); CCPhysicsBody other = (joint.GetBodyA() == body ? joint.GetBodyB() : joint.GetBodyA()); other.RemoveJoint(joint); if (_delayRemoveJoints.Exists(j => j == joint)) { joint._destoryMark = true; } } body._joints.Clear(); RemoveBodyOrDelay(body); _bodies.Remove(body); body._world = null; }
protected bool Init(CCPhysicsBody a, CCPhysicsBody b, CCPoint anchr1, CCPoint anchr2, float stiffness, float damping) { if (!base.Init(a, b)) { return(false); } var anch1 = PhysicsHelper.CCPointToCpVect(anchr1); var anch2 = PhysicsHelper.CCPointToCpVect(anchr2); cpConstraint joint = new cpDampedSpring(GetBodyInfo(a).Body, GetBodyInfo(b).Body, anch1, anch2, cpVect.cpvdist( _bodyB.Local2World(anch1), _bodyA.Local2World(anch2)), stiffness, damping); if (joint == null) { return(false); } _info.Add(joint); return(true); }
/** Create a body contains a circle shape. */ public static CCPhysicsBody CreateCircle(float radius, CCPhysicsMaterial material, CCPoint offset) { CCPhysicsBody body = new CCPhysicsBody(); body.AddShape(new CCPhysicsShapeCircle(material, radius, offset)); return(body); }
/** Create a body contains a box shape. */ public static CCPhysicsBody CreateBox(CCSize size, CCPhysicsMaterial material, float radius) { CCPhysicsBody body = new CCPhysicsBody(); body.AddShape(new CCPhysicsShapeBox(size, material, radius)); return(body); }
public virtual CCPhysicsBody AddBodyOrDelay(CCPhysicsBody body) { CCPhysicsBody removeBodyIter = _delayRemoveBodies.Find(b => b == body); if (removeBodyIter != null) { _delayRemoveBodies.Remove(removeBodyIter); return(null); } if (_info.isLocked()) { if (_delayAddBodies.Exists(b => b == body)) { _delayAddBodies.Add(body); _delayDirty = true; } } else { DoAddBody(body); } return(body); }
/** * @brief Create a body contains a polygon shape. * points is an array of cpVect structs defining a convex hull with a clockwise winding. */ public static CCPhysicsBody CreatePolygon(CCPoint[] points, int count, CCPhysicsMaterial material, float radius) { CCPhysicsBody body = new CCPhysicsBody(); body.AddShape(new CCPhysicsShapePolygon(points, count, material, radius)); return(body); }
public virtual void UpdateBodies() { if (_info.isLocked()) { return; } // Fixed: netonjm > issue #4944, contact callback will be invoked when add/remove body, _delayAddBodies maybe changed, so we need make a copy. CCPhysicsBody[] addCopy = new CCPhysicsBody[_delayAddBodies.Count]; _delayAddBodies.CopyTo(addCopy); _delayAddBodies.Clear(); foreach (var body in addCopy) { DoAddBody(body); } CCPhysicsBody[] removeCopy = new CCPhysicsBody[_delayRemoveBodies.Count]; _delayRemoveBodies.CopyTo(removeCopy); _delayRemoveBodies.Clear(); foreach (var body in removeCopy) { DoRemoveBody(body); } }
/** Create a body contains a EdgeSegment shape. */ public static CCPhysicsBody CreateEdgeSegment(CCPoint a, CCPoint b, CCPhysicsMaterial material, float border = 1) { CCPhysicsBody body = new CCPhysicsBody(); body.AddShape(new CCPhysicsShapeEdgeSegment(a, b, material, border)); body.IsDynamic = false; return(body); }
/** Create a body contains a EdgeBox shape. */ public static CCPhysicsBody CreateEdgeBox(CCSize size, CCPhysicsMaterial material, float border, CCPoint offset) { CCPhysicsBody body = new CCPhysicsBody(); body.AddShape(new CCPhysicsShapeEdgeBox(size, material, offset, border)); body.IsDynamic = false; return(body); }
/** Create a body contains a EdgeChain shape. */ public static CCPhysicsBody CreateEdgeChain(CCPoint[] points, int count, CCPhysicsMaterial material, float border = 1) { CCPhysicsBody body = new CCPhysicsBody(); body.AddShape(new CCPhysicsShapeEdgeChain(points, count, material, border)); body.IsDynamic = false; return(body); }
public static CCPhysicsJointSpring Construct(CCPhysicsBody a, CCPhysicsBody b, CCPoint anchr1, CCPoint anchr2, float stiffness, float damping) { CCPhysicsJointSpring joint = new CCPhysicsJointSpring(); if (joint != null && joint.Init(a, b, anchr1, anchr2, stiffness, damping)) { return(joint); } return(null); }
public static CCPhysicsJointDistance Construct(CCPhysicsBody a, CCPhysicsBody b, CCPoint anchr1, CCPoint anchr2) { CCPhysicsJointDistance joint = new CCPhysicsJointDistance(); if (joint != null && joint.Init(a, b, PhysicsHelper.CCPointToCpVect(anchr1), PhysicsHelper.CCPointToCpVect(anchr2))) { return(joint); } return(null); }
public static CCPhysicsJointGroove Construct(CCPhysicsBody a, CCPhysicsBody b, CCPoint grooveA, CCPoint grooveB, CCPoint anchr2) { CCPhysicsJointGroove joint = new CCPhysicsJointGroove(); if (joint != null && joint.Init(a, b, grooveA, grooveB, anchr2)) { return(joint); } return(null); }
public CCPhysicsJoint() { _bodyA = null; _bodyB = null; _world = null; _info = null; _enable = false; _collisionEnable = true; _destoryMark = false; _tag = 0; }
public static CCPhysicsJointPin Construct(CCPhysicsBody a, CCPhysicsBody b, CCPoint anchr) { CCPhysicsJointPin joint = new CCPhysicsJointPin(); if (joint != null && joint.Init(a, b, anchr)) { return(joint); } return(null); }
public static CCPhysicsJointRotaryLimit Construct(CCPhysicsBody a, CCPhysicsBody b, float min, float max) { CCPhysicsJointRotaryLimit joint = new CCPhysicsJointRotaryLimit(); if (joint != null && joint.Init(a, b, min, max)) { return(joint); } return(null); }
public static CCPhysicsJointMotor Construct(CCPhysicsBody a, CCPhysicsBody b, float rate) { CCPhysicsJointMotor joint = new CCPhysicsJointMotor(); if (joint != null && joint.Init(a, b, rate)) { return(joint); } return(null); }
public static CCPhysicsJointGear Construct(CCPhysicsBody a, CCPhysicsBody b, float phase, float ratio) { CCPhysicsJointGear joint = new CCPhysicsJointGear(); if (joint != null && joint.Init(a, b, phase, ratio)) { return(joint); } return(null); }
public static CCPhysicsJointRatchet Construct(CCPhysicsBody a, CCPhysicsBody b, float phase, float ratchet) { CCPhysicsJointRatchet joint = new CCPhysicsJointRatchet(); if (joint != null && joint.Init(a, b, phase, ratchet)) { return(joint); } return(null); }
public static CCPhysicsJointFixed Construct(CCPhysicsBody a, CCPhysicsBody b, CCPoint anchr) { CCPhysicsJointFixed joint = new CCPhysicsJointFixed(); if (joint != null && joint.Init(a, b, anchr)) { return(joint); } // CC_SAFE_DELETE(joint); return(null); }
protected bool Init(CCPhysicsBody a, CCPhysicsBody b) { cp.AssertWarn(a != null && b != null, "the body passed in is nil"); cp.AssertWarn(a != b, "the two bodies are equal"); _info = new CCPhysicsJointInfo(this); if (_info != null) { return(false); } _bodyA = a; _bodyA._joints.Add(this); _bodyB = b; _bodyB._joints.Add(this); return(true); }
public virtual void DoRemoveBody(CCPhysicsBody body) { cp.AssertWarn(body != null, "the body can not be nullptr"); // reset the gravity if (!body.IsGravityEnabled()) { body.ApplyForce(_gravity * body.GetMass()); } // remove shaps foreach (var shape in body.GetShapes()) { RemoveShape(shape); } // remove body _info.removeBody(body._info); }
//static PhysicsJointPin* ruct(PhysicsBody* a, PhysicsBody* b, cpVect anchr); #region PROTECTED FUNC protected bool Init(CCPhysicsBody a, CCPhysicsBody b, CCPoint anchr) { if (!base.Init(a, b)) { return(false); } cpConstraint joint = new cpPivotJoint(GetBodyInfo(a).Body, GetBodyInfo(b).Body, PhysicsHelper.CCPointToCpVect(anchr)); if (joint == null) { return(false); } _info.Add(joint); return(true); }
public virtual CCPhysicsBody AddBody(CCPhysicsBody body) { cp.AssertWarn(body != null, "the body can not be nullptr"); if (body.GetWorld() == this) { return(null); } if (body.GetWorld() != null) { body.RemoveFromWorld(); } AddBodyOrDelay(body); _bodies.Add(body); body._world = this; return(body); }
protected bool Init(CCPhysicsBody a, CCPhysicsBody b, float rate) { if (!base.Init(a, b)) { return(false); } cpConstraint joint = new cpSimpleMotor(GetBodyInfo(a).Body, GetBodyInfo(b).Body, rate); if (joint == null) { return(false); } _info.Add(joint); return(true); }
protected bool Init(CCPhysicsBody a, CCPhysicsBody b, float phase, float ratio) { if (!base.Init(a, b)) { return(false); } cpConstraint joint = new cpGearJoint(GetBodyInfo(a).Body, GetBodyInfo(b).Body, phase, ratio); if (joint == null) { return(false); } _info.Add(joint); return(true); }
bool Init(CCPhysicsBody a, CCPhysicsBody b, cpVect anchr1, cpVect anchr2) { if (!base.Init(a, b)) { return(false); } cpConstraint joint = new cpPinJoint(GetBodyInfo(a).Body, GetBodyInfo(b).Body, anchr1, anchr2); if (joint == null) { return(false); } _info.Add(joint); return(true); }
protected bool Init(CCPhysicsBody a, CCPhysicsBody b, float min, float max) { if (!base.Init(a, b)) { return(false); } cpConstraint joint = new cpRotaryLimitJoint(GetBodyInfo(a).Body, GetBodyInfo(b).Body, min, max); if (joint == null) { return(false); } _info.Add(joint); return(true); }
public virtual void RemoveBodyOrDelay(CCPhysicsBody body) { if (_delayAddBodies.Exists(b => b == body)) { _delayAddBodies.Remove(body); return; } if (_info.isLocked()) { if (_delayRemoveBodies.Exists(b => b == body)) { _delayRemoveBodies.Add(body); _delayDirty = true; } } else { DoRemoveBody(body); } }
public CCPhysicsShape() { _body = null; _info = null; _type = PhysicsType.UNKNOWN; _area = 0; _mass = CCPhysicsBody.MASS_DEFAULT; _moment = CCPhysicsBody.MOMENT_DEFAULT; _tag = 0; _categoryBitmask = int.MaxValue; _collisionBitmask = int.MaxValue; _contactTestBitmask = 0; _group = 0; _info = new CCPhysicsShapeInfo(this); _scaleX = 1.0f; _scaleY = 1.0f; _newScaleX = 1.0f; _newScaleY = 1.0f; _dirty = false; }
public virtual void DoAddBody(CCPhysicsBody body) { if (body.IsEnabled()) { //is gravity enable if (!body.IsGravityEnabled()) { body.ApplyForce(-_gravity * body.GetMass()); } // add body to space if (body.IsDynamic()) { _info.addBody(body._info); } // add shapes to space foreach (CCPhysicsShape shape in body.GetShapes()) { AddShape(shape); } } }
public virtual CCPhysicsBody AddBody(CCPhysicsBody body) { cp.AssertWarn(body != null, "the body can not be nullptr"); if (body.GetWorld() == this) return null; if (body.GetWorld() != null) { body.RemoveFromWorld(); } AddBodyOrDelay(body); _bodies.Add(body); body._world = this; return body; }
/** Remove a body from physics world. */ public virtual void RemoveBody(CCPhysicsBody body) { if (body.GetWorld() != this) { cp.AssertWarn("Physics Warnning: this body doesn't belong to this world"); return; } // destory the body's joints foreach (var joint in body._joints) { // set destroy param to false to keep the iterator available RemoveJoint(joint, false); CCPhysicsBody other = (joint.GetBodyA() == body ? joint.GetBodyB() : joint.GetBodyA()); other.RemoveJoint(joint); if (_delayRemoveJoints.Exists(j => j == joint)) joint._destoryMark = true; } body._joints.Clear(); RemoveBodyOrDelay(body); _bodies.Remove(body); body._world = null; }
protected int lookupBodyIndex(CCPhysicsBody body) { int? val = m_bodyToIndexMap[body]; if (null != val) return val.Value; else return -1; }
public string GetBodyName(CCPhysicsBody body) { if (m_bodyToNameMap.ContainsKey(body)) return m_bodyToNameMap[body]; return null; }
// REVISADO ===================================================================== public void SetBodyTypeFromInt(CCPhysicsBody body, int type) { switch (type) { case 0: body.BodyType = cpBodyType.STATIC; //body = CCPhysicsBody.NewStatic(); // CCPhysicsBodyType.b2_staticBody; break; case 1: //body = CCPhysicsBody.NewKinematic(); // CCPhysicsBodyType.b2_kinematicBody; body.BodyType = cpBodyType.KINEMATIC; break; //default: // body = CCPhysicsBody.New(1,1); // = CCPhysicsBodyType.b2_dynamicBody; // break; } }
public void SetCustomString(CCPhysicsBody item, String propertyName, String val) { m_bodiesWithCustomProperties.Add(item); GetCustomPropertiesForItem(item, true).m_customPropertyMap_string.Add(propertyName, val); }
/** Create a body contains a circle shape. */ public static CCPhysicsBody CreateCircle(float radius, CCPhysicsMaterial material, CCPoint offset) { CCPhysicsBody body = new CCPhysicsBody(); body.AddShape(new CCPhysicsShapeCircle(material, radius, offset)); return body; }
/** * @brief Create a body contains a polygon shape. * points is an array of cpVect structs defining a convex hull with a clockwise winding. */ public static CCPhysicsBody CreatePolygon(CCPoint[] points, int count, CCPhysicsMaterial material, float radius) { CCPhysicsBody body = new CCPhysicsBody(); body.AddShape(new CCPhysicsShapePolygon(points, count, material, radius)); return body; }
public virtual CCPhysicsBody AddBodyOrDelay(CCPhysicsBody body) { CCPhysicsBody removeBodyIter = _delayRemoveBodies.Find(b => b == body); if (removeBodyIter != null) { _delayRemoveBodies.Remove(removeBodyIter); return null; } if (_info.isLocked()) { if (_delayAddBodies.Exists(b => b == body)) { _delayAddBodies.Add(body); _delayDirty = true; } } else { DoAddBody(body); } return body; }
/** Create a body contains a EdgeBox shape. */ public static CCPhysicsBody CreateEdgeBox(CCSize size, CCPhysicsMaterial material, float border, CCPoint offset) { CCPhysicsBody body = new CCPhysicsBody(); body.AddShape(new CCPhysicsShapeEdgeBox(size, material, offset, border)); body.IsDynamic = false; return body; }
public override void OnEnter() { base.OnEnter(); float width = (VisibleBoundsWorldspace.Size.Width - 10) / 4; float height = (VisibleBoundsWorldspace.Size.Height - 50) / 4; Scene.PhysicsWorld.DebugDrawMask = PhysicsDrawFlags.Shapes | PhysicsDrawFlags.Joints; CCNode node = new CCNode(); CCPhysicsBody box = new CCPhysicsBody(); node.PhysicsBody = box; box.IsDynamic = false; node.Position = CCPoint.Zero; AddChild(node); CCPhysicsJoint joint; CCSprite sp1, sp2; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { CCPoint offset = new CCPoint( 0 + 5 + j * width + width / 2, 0 + 50 + i * height + height / 2 ); //CCPoint offset = new CCPoint() box.AddShape( new CCPhysicsShapeEdgeBox( new CCSize(width, height), CCPhysicsMaterial.PHYSICSSHAPE_MATERIAL_DEFAULT, offset, 1) ); switch (i * 4 + j) { case 0: sp1 = MakeBall(offset - new CCPoint(30, 0), 10); sp1.PhysicsBody.Tag = DRAG_BODYS_TAG; sp2 = MakeBall(offset + new CCPoint(30, 0), 10); sp2.PhysicsBody.Tag = DRAG_BODYS_TAG; joint = CCPhysicsJointPin.Construct(sp1.PhysicsBody, sp2.PhysicsBody, offset); Scene.PhysicsWorld.AddJoint(joint); AddChild(sp1); AddChild(sp2); break; case 1: sp1 = MakeBall(offset - new CCPoint(30, 0), 10); sp1.PhysicsBody.Tag = DRAG_BODYS_TAG; sp2 = MakeBox(offset + new CCPoint(30, 0), new CCSize(30, 10)); sp2.PhysicsBody.Tag = DRAG_BODYS_TAG; joint = CCPhysicsJointFixed.Construct(sp1.PhysicsBody, sp2.PhysicsBody, offset); Scene.PhysicsWorld.AddJoint(joint); AddChild(sp1); AddChild(sp2); break; case 2: sp1 = MakeBall(offset - new CCPoint(30, 0), 10); sp1.PhysicsBody.Tag = DRAG_BODYS_TAG; sp2 = MakeBox(offset + new CCPoint(30, 0), new CCSize(30, 10)); sp2.PhysicsBody.Tag = DRAG_BODYS_TAG; joint = CCPhysicsJointDistance.Construct(sp1.PhysicsBody, sp2.PhysicsBody, CCPoint.Zero, CCPoint.Zero); Scene.PhysicsWorld.AddJoint(joint); AddChild(sp1); AddChild(sp2); break; case 3: sp1 = MakeBall(offset - new CCPoint(30, 0), 10); sp1.PhysicsBody.Tag = DRAG_BODYS_TAG; sp2 = MakeBox(offset + new CCPoint(30, 0), new CCSize(30, 10)); sp2.PhysicsBody.Tag = DRAG_BODYS_TAG; joint = CCPhysicsJointSpring.Construct(sp1.PhysicsBody, sp2.PhysicsBody, CCPoint.Zero, CCPoint.Zero, 500, 0.3f); Scene.PhysicsWorld.AddJoint(joint); AddChild(sp1); AddChild(sp2); break; case 4: sp1 = MakeBall(offset - new CCPoint(30, 0), 10); sp1.PhysicsBody.Tag = DRAG_BODYS_TAG; sp2 = MakeBox(offset + new CCPoint(30, 0), new CCSize(30, 10)); sp2.PhysicsBody.Tag = DRAG_BODYS_TAG; joint = CCPhysicsJointGroove.Construct(sp1.PhysicsBody, sp2.PhysicsBody, new CCPoint(30, 15), new CCPoint(30, -15), new CCPoint(-30, 0)); Scene.PhysicsWorld.AddJoint(joint); AddChild(sp1); AddChild(sp2); break; case 5: sp1 = MakeBall(offset - new CCPoint(30, 0), 10); sp1.PhysicsBody.Tag = DRAG_BODYS_TAG; sp2 = MakeBox(offset + new CCPoint(30, 0), new CCSize(30, 10)); sp2.PhysicsBody.Tag = DRAG_BODYS_TAG; joint = CCPhysicsJointGroove.Construct(sp1.PhysicsBody, sp2.PhysicsBody, new CCPoint(30, 15), new CCPoint(30, -15), new CCPoint(-30, 0)); Scene.PhysicsWorld.AddJoint(joint); AddChild(sp1); AddChild(sp2); break; case 6: sp1 = MakeBox(offset - new CCPoint(30, 0), new CCSize(30, 10)); sp1.PhysicsBody.Tag = DRAG_BODYS_TAG; sp2 = MakeBox(offset + new CCPoint(30, 0), new CCSize(30, 10)); sp2.PhysicsBody.Tag = DRAG_BODYS_TAG; Scene.PhysicsWorld.AddJoint(CCPhysicsJointPin.Construct(sp1.PhysicsBody, sp2.PhysicsBody, sp1.Position)); Scene.PhysicsWorld.AddJoint(CCPhysicsJointPin.Construct(sp1.PhysicsBody, sp2.PhysicsBody, sp1.Position)); joint = CCPhysicsJointRotarySpring.Construct(sp1.PhysicsBody, sp2.PhysicsBody, 3000.0f, 60.0f); Scene.PhysicsWorld.AddJoint(joint); AddChild(sp1); AddChild(sp2); break; case 7: sp1 = MakeBox(offset - new CCPoint(30, 0), new CCSize(30, 10)); sp1.PhysicsBody.Tag = DRAG_BODYS_TAG; sp2 = MakeBox(offset + new CCPoint(30, 0), new CCSize(30, 10)); sp2.PhysicsBody.Tag = DRAG_BODYS_TAG; Scene.PhysicsWorld.AddJoint(CCPhysicsJointPin.Construct(sp1.PhysicsBody, sp2.PhysicsBody, sp1.Position)); Scene.PhysicsWorld.AddJoint(CCPhysicsJointPin.Construct(sp1.PhysicsBody, sp2.PhysicsBody, sp1.Position)); joint = CCPhysicsJointRotaryLimit.Construct(sp1.PhysicsBody, sp2.PhysicsBody, 0.0f, ChipmunkSharp.cp.M_PI_2); Scene.PhysicsWorld.AddJoint(joint); AddChild(sp1); AddChild(sp2); break; case 8: sp1 = MakeBox(offset - new CCPoint(30, 0), new CCSize(30, 10)); sp1.PhysicsBody.Tag = DRAG_BODYS_TAG; sp2 = MakeBox(offset + new CCPoint(30, 0), new CCSize(30, 10)); sp2.PhysicsBody.Tag = DRAG_BODYS_TAG; Scene.PhysicsWorld.AddJoint(CCPhysicsJointPin.Construct(sp1.PhysicsBody, sp2.PhysicsBody, sp1.Position)); Scene.PhysicsWorld.AddJoint(CCPhysicsJointPin.Construct(sp1.PhysicsBody, sp2.PhysicsBody, sp1.Position)); joint = CCPhysicsJointRatchet.Construct(sp1.PhysicsBody, sp2.PhysicsBody, 0.0f, ChipmunkSharp.cp.M_PI_2); Scene.PhysicsWorld.AddJoint(joint); AddChild(sp1); AddChild(sp2); break; case 9: sp1 = MakeBox(offset - new CCPoint(30, 0), new CCSize(30, 10)); sp1.PhysicsBody.Tag = DRAG_BODYS_TAG; sp2 = MakeBox(offset + new CCPoint(30, 0), new CCSize(30, 10)); sp2.PhysicsBody.Tag = DRAG_BODYS_TAG; Scene.PhysicsWorld.AddJoint(CCPhysicsJointPin.Construct(sp1.PhysicsBody, sp2.PhysicsBody, sp1.Position)); Scene.PhysicsWorld.AddJoint(CCPhysicsJointPin.Construct(sp1.PhysicsBody, sp2.PhysicsBody, sp1.Position)); joint = CCPhysicsJointGear.Construct(sp1.PhysicsBody, sp2.PhysicsBody, 0.0f, 2f); Scene.PhysicsWorld.AddJoint(joint); AddChild(sp1); AddChild(sp2); break; case 10: sp1 = MakeBox(offset - new CCPoint(30, 0), new CCSize(30, 10)); sp1.PhysicsBody.Tag = DRAG_BODYS_TAG; sp2 = MakeBox(offset + new CCPoint(30, 0), new CCSize(30, 10)); sp2.PhysicsBody.Tag = DRAG_BODYS_TAG; Scene.PhysicsWorld.AddJoint(CCPhysicsJointPin.Construct(sp1.PhysicsBody, sp2.PhysicsBody, sp1.Position)); Scene.PhysicsWorld.AddJoint(CCPhysicsJointPin.Construct(sp1.PhysicsBody, sp2.PhysicsBody, sp1.Position)); joint = CCPhysicsJointMotor.Construct(sp1.PhysicsBody, sp2.PhysicsBody, ChipmunkSharp.cp.M_PI_2); Scene.PhysicsWorld.AddJoint(joint); AddChild(sp1); AddChild(sp2); break; default: break; } } } Schedule(); }
protected void readCustomPropertiesFromJson(CCPhysicsBody item, JObject value) { if (null == item) return; if (value["customProperties"] != null) return; int i = 0; JArray propValues = (JArray)value["customProperties"]; if (null != propValues) { int numPropValues = propValues.Count; for (i = 0; i < numPropValues; i++) { JObject propValue = (JObject)propValues[i]; string propertyName = propValue["name"].ToString(); if (propValue["int"] != null) SetCustomInt(item, propertyName, (int)propValue["int"]); if (propValue["float"] != null) SetCustomFloat(item, propertyName, (float)propValue["float"]); if (propValue["string"] != null) SetCustomString(item, propertyName, propValue["string"].ToString()); if (propValue["vec2"] != null) SetCustomVector(item, propertyName, this.jsonToVec("vec2", propValue)); if (propValue["bool"] != null) SetCustomBool(item, propertyName, (bool)propValue["bool"]); } } }
public static CCPhysicsJointRatchet Construct(CCPhysicsBody a, CCPhysicsBody b, float phase, float ratchet) { CCPhysicsJointRatchet joint = new CCPhysicsJointRatchet(); if (joint != null && joint.Init(a, b, phase, ratchet)) { return joint; } return null; }
//public JObject writeToValue( b2World world) { //if (null == world) // return new JObject(); //return b2j(world); //} //public String worldToString(b2World world, int indentFactor) { // if (null == world) // return ""; // return b2j(world).toString(indentFactor); //} public void SetBodyName(CCPhysicsBody body, String name) { m_bodyToNameMap.Add(body, name); }
public static CCPhysicsJointGear Construct(CCPhysicsBody a, CCPhysicsBody b, float phase, float ratio) { CCPhysicsJointGear joint = new CCPhysicsJointGear(); if (joint != null && joint.Init(a, b, phase, ratio)) { return joint; } return null; }
public void SetCustomFloat(CCPhysicsBody item, String propertyName, float val) { m_bodiesWithCustomProperties.Add(item); GetCustomPropertiesForItem(item, true).m_customPropertyMap_float.Add(propertyName, (float)val); }
protected bool Init(CCPhysicsBody a, CCPhysicsBody b, float phase, float ratio) { if (!base.Init(a, b)) return false; cpConstraint joint = new cpGearJoint(GetBodyInfo(a).Body, GetBodyInfo(b).Body, phase, ratio); if (joint == null) return false; _info.Add(joint); return true; }
public void SetCustomVector(CCPhysicsBody item, String propertyName, cpVect val) { m_bodiesWithCustomProperties.Add(item); GetCustomPropertiesForItem(item, true).m_customPropertyMap_cpVect.Add(propertyName, val); }
public static CCPhysicsJointMotor Construct(CCPhysicsBody a, CCPhysicsBody b, float rate) { CCPhysicsJointMotor joint = new CCPhysicsJointMotor(); if (joint != null && joint.Init(a, b, rate)) { return joint; } return null; }
/** Create a body contains a box shape. */ public static CCPhysicsBody CreateBox(CCSize size, CCPhysicsMaterial material, float radius) { CCPhysicsBody body = new CCPhysicsBody(); body.AddShape(new CCPhysicsShapeBox(size, material, radius)); return body; }
protected bool Init(CCPhysicsBody a, CCPhysicsBody b, float rate) { if (!base.Init(a, b)) return false; cpConstraint joint = new cpSimpleMotor(GetBodyInfo(a).Body, GetBodyInfo(b).Body, rate); if (joint == null) return false; _info.Add(joint); return true; }
/** Create a body contains a EdgeSegment shape. */ public static CCPhysicsBody CreateEdgeSegment(CCPoint a, CCPoint b, CCPhysicsMaterial material, float border = 1) { CCPhysicsBody body = new CCPhysicsBody(); body.AddShape(new CCPhysicsShapeEdgeSegment(a, b, material, border)); body.IsDynamic = false; return body; }
/** Create a body contains a EdgeChain shape. */ public static CCPhysicsBody CreateEdgeChain(CCPoint[] points, int count, CCPhysicsMaterial material, float border = 1) { CCPhysicsBody body = new CCPhysicsBody(); body.AddShape(new CCPhysicsShapeEdgeChain(points, count, material, border)); body.IsDynamic = false; return body; }
public override void OnEnter() { base.OnEnter(); ToggleDebug(); _distance = 0.0f; _rotationV = 0.0f; Scene.Scale = 0.5f; //Create a boundin box container room var node = new CCNode(); var body = new CCPhysicsBody(); body.IsDynamic = false; CCPhysicsMaterial staticMaterial = new CCPhysicsMaterial(cp.PHYSICS_INFINITY, 0, 0.5f); body.AddShape(new CCPhysicsShapeEdgeSegment(LeftTop + new CCPoint(50, 0), LeftTop + new CCPoint(50, -130), staticMaterial, 2.0f)); body.AddShape(new CCPhysicsShapeEdgeSegment(LeftTop + new CCPoint(190, 0), LeftTop + new CCPoint(100, -50), staticMaterial, 2.0f)); body.AddShape(new CCPhysicsShapeEdgeSegment(LeftTop + new CCPoint(100, -50), LeftTop + new CCPoint(100, -90), staticMaterial, 2.0f)); body.AddShape(new CCPhysicsShapeEdgeSegment(LeftTop + new CCPoint(50, -130), LeftTop + new CCPoint(100, -145), staticMaterial, 2.0f)); body.AddShape(new CCPhysicsShapeEdgeSegment(LeftTop + new CCPoint(100, -145), LeftBottom + new CCPoint(100, 80), staticMaterial, 2.0f)); body.AddShape(new CCPhysicsShapeEdgeSegment(LeftTop + new CCPoint(150, -80), LeftBottom + new CCPoint(150, 80), staticMaterial, 2.0f)); body.AddShape(new CCPhysicsShapeEdgeSegment(LeftTop + new CCPoint(150, -80), RightTop + new CCPoint(-100, -150), staticMaterial, 2.0f)); body.SetCategoryBitmask(0x01); for (int i = 0; i < 6; ++i) { var ball = MakeBall(LeftTop + new CCPoint(75 + CCRandom.Float_0_1() * 90, 0), 22, new CCPhysicsMaterial(0.05f, 0, 0.1f)); ball.PhysicsBody.Tag = DRAG_BODYS_TAG; AddChild(ball); } node.PhysicsBody = body; AddChild(node); CCPoint[] vec = new CCPoint[4] { new CCPoint(LeftTop + new CCPoint(102,-148)), new CCPoint(LeftTop + new CCPoint(148,-161)), new CCPoint(LeftBottom + new CCPoint(148,20)), new CCPoint(LeftBottom + new CCPoint(102,20)) }; var world = Scene.PhysicsWorld; // small gear var sgear = new CCNode();// Node::create(); var sgearB = CCPhysicsBody.CreateCircle(44, CCPoint.Zero); sgear.PhysicsBody = sgearB; sgear.Position = LeftBottom + new CCPoint(125, 0); this.AddChild(sgear); //sgearB.SetCategoryBitmask(0x04); //sgearB.SetCollisionBitmask(0x04); sgearB.Tag = 1; world.AddJoint(CCPhysicsJointPin.Construct(body, sgearB, sgearB.Position)); // big gear var bgear = new CCNode(); var bgearB = CCPhysicsBody.CreateCircle(100); bgear.PhysicsBody = (bgearB); bgear.Position = LeftBottom + new CCPoint(275, 0); this.AddChild(bgear); //bgearB.SetCategoryBitmask(0x04); world.AddJoint(CCPhysicsJointPin.Construct(body, bgearB, bgearB.Position)); // pump var pump = new CCNode(); var center = CCPhysicsShape.GetPolygonCenter(vec, 4); pump.Position = center; var pumpB = CCPhysicsBody.CreatePolygon(vec, 4, CCPhysicsMaterial.PHYSICSSHAPE_MATERIAL_DEFAULT, 0.0f); pump.PhysicsBody = pumpB; this.AddChild(pump); //pumpB.SetCategoryBitmask(0x02); pumpB.SetGravityEnable(false); world.AddJoint(CCPhysicsJointDistance.Construct(pumpB, sgearB, new CCPoint(0, 0), new CCPoint(0, -44))); // plugger CCPoint[] seg = new CCPoint[] { LeftTop + new CCPoint(75, -120), LeftBottom + new CCPoint(75, -100) }; CCPoint segCenter = (seg[1] + seg[0]) / 2; seg[1] -= segCenter; seg[0] -= segCenter; var plugger = new CCNode(); var pluggerB = CCPhysicsBody.CreateEdgeSegment(seg[0], seg[1], new CCPhysicsMaterial(0.01f, 0.0f, 0.5f), 20); pluggerB.IsDynamic = true; pluggerB.SetMass(30); pluggerB.Moment = 100000; plugger.PhysicsBody = pluggerB; plugger.Position = segCenter; this.AddChild(plugger); //pluggerB.SetCategoryBitmask(0x02); //sgearB.SetCollisionBitmask(0x04 | 0x01); world.AddJoint(CCPhysicsJointPin.Construct(body, pluggerB, LeftBottom + new CCPoint(75, -90))); world.AddJoint(CCPhysicsJointDistance.Construct(pluggerB, sgearB, pluggerB.World2Local(LeftBottom + new CCPoint(75, 0)), new CCPoint(44, 0))); //drops a grosini sprite on center on window Schedule(); }