SetUserData() публичный Метод

Set the user data. Use this to store your application specific data.
public SetUserData ( object data ) : void
data object
Результат void
        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
0
        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);
        }