本文整理汇总了C#中Box2DX.Dynamics.Body.SetUserData方法的典型用法代码示例。如果您正苦于以下问题:C# Body.SetUserData方法的具体用法?C# Body.SetUserData怎么用?C# Body.SetUserData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Box2DX.Dynamics.Body
的用法示例。
在下文中一共展示了Body.SetUserData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddToWorld
public void AddToWorld()
{
body = world.CreateBody(bodyDef);
foreach (ShapeDef shape in shapes)
body.CreateShape(shape);
body.SetMassFromShapes();
body.SetUserData(this);
foreach (Controller controller in controllers)
{
controller.AddBody(body);
world.AddController(controller);
}
foreach (PhysicsObject child in children)
child.AddToWorld();
}
示例2: PlayerCharacter
public PlayerCharacter(World _world, Vector2 _position)
: base(_world, _position)
{
playerIndex = playerCount++;
color = PlayerCharacter.Colors[playerIndex];
accelerate = 0;
rotate = 0;
isDead = false;
this.angVelocity = 0;
//build the unicycle
CircleDef circleDef = new CircleDef();
circleDef.Radius = 1;
circleDef.Density = 1f;
circleDef.Friction = 1.0f;
circleDef.Restitution = 0.0f;
circleDef.LocalPosition.Set(0, 0);
wheel = body.CreateShape(circleDef);
body.SetMassFromShapes();
body.SetUserData(this); // link body and this to register collisions in this
//build the head and connect with the wheel
BodyDef bodydef = new BodyDef();
bodydef.Position = _position + new Vector2(0.0f, 3.5f);
bodydef.Angle = 0f;
chest = _world.CreateBody(bodydef);
//add the head
circleDef.Density = 0.0001f;
circleDef.Radius = 0.75f;
circleDef.LocalPosition.Set(0, 3);
head = chest.CreateShape(circleDef);
rotationHead = _position;
PolygonDef Boxdef = new PolygonDef();
Boxdef.SetAsBox(1, 1.5f);
Boxdef.Density = 0.25f;
Boxdef.Friction = 0.4f;
Box2DX.Collision.Shape s2 = chest.CreateShape(Boxdef);
chest.SetMassFromShapes();
chest.SetUserData(this);
//Jointshit
RevoluteJointDef jointDefKW = new RevoluteJointDef();
jointDefKW.Body2 = chest;
jointDefKW.Body1 = body;
jointDefKW.CollideConnected = false;
jointDefKW.LocalAnchor2 = new Vector2(-0.0f, -3.8f);
jointDefKW.LocalAnchor1 = new Vector2(0, 0);
jointDefKW.EnableLimit = false;
_world.CreateJoint(jointDefKW);
// add visuals
Texture wheelTexture = AssetManager.getTexture(AssetManager.TextureName.ShoopWheel);
wheelSprite = new AnimatedSprite(wheelTexture, 1.0f, 1, (Vector2)wheelTexture.Size);
wheelSprite.Scale = Constants.windowScaleFactor * new Vector2(0.2f, 0.2f); //(Vector2.One / (Vector2)wheelTexture.Size * 2F * circleDef.Radius).toScreenCoord() - Vector2.Zero.toScreenCoord();//new Vector2(0.08f, 0.08f);
wheelSprite.Origin = ((Vector2)wheelSprite.spriteSize) / 2F;
sheepSprite = new Sprite(AssetManager.getTexture(AssetManager.TextureName.ShoopInfronUnicycle));
sheepSprite.Origin = ((Vector2)sheepSprite.Texture.Size) / 2F;
sheepSprite.Scale = Constants.windowScaleFactor * new Vector2(_position.X > Constants.worldSizeX / 2F ? -0.2f : 0.2f, 0.2f);
}