本文整理汇总了C#中CocosSharp.CCPhysicsBody类的典型用法代码示例。如果您正苦于以下问题:C# CCPhysicsBody类的具体用法?C# CCPhysicsBody怎么用?C# CCPhysicsBody使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CCPhysicsBody类属于CocosSharp命名空间,在下文中一共展示了CCPhysicsBody类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Construct
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;
}
示例2: CreateEdgeBox
/** 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;
}
示例3: CreatePolygon
/**
* @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;
}
示例4: CreateCircle
/** 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;
}
示例5: SetCustomString
public void SetCustomString(CCPhysicsBody item, String propertyName, String val)
{
m_bodiesWithCustomProperties.Add(item);
GetCustomPropertiesForItem(item, true).m_customPropertyMap_string.Add(propertyName, val);
}
示例6: SetBodyTypeFromInt
// 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;
}
}
示例7: GetBodyName
public string GetBodyName(CCPhysicsBody body)
{
if (m_bodyToNameMap.ContainsKey(body))
return m_bodyToNameMap[body];
return null;
}
示例8: OnEnter
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);
//.........这里部分代码省略.........
示例9: CCPhysicsShape
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;
}
示例10: Init
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;
}
示例11: lookupBodyIndex
protected int lookupBodyIndex(CCPhysicsBody body)
{
int? val = m_bodyToIndexMap[body];
if (null != val)
return val.Value;
else
return -1;
}
示例12: readCustomPropertiesFromJson
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"]);
}
}
}
示例13: UpdateBodies
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);
}
}
示例14: SetBodyName
//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);
}
示例15: RemoveBody
/** 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;
}