Exemplo n.º 1
0
 public Sprite ToSprite()
 {
     var tex = XNADevicesManager.Instance.ContentManager.Load<Texture2D>(TexName);
     Sprite sprite;
     if (RepeatX != 0.0f || RepeatY != 0.0f)
     {
         var rSprite = new RepeatSprite(tex);
         rSprite.RepeatX = RepeatX;
         rSprite.RepeatY = RepeatY;
         sprite = rSprite;
     }
     else
     {
         sprite = new Sprite(tex);
     }
     sprite.DrawRectangle = DrawRectangle;
     sprite.Alpha = Alpha;
     sprite.ScaleX = ScaleX;
     sprite.ScaleY = ScaleY;
     sprite.RotateX = RotateX;
     sprite.RotateY = RotateY;
     sprite.RotateZ = RotateZ;
     sprite.R = R;
     sprite.G = G;
     sprite.B = B;
     sprite.X = X;
     sprite.Y = Y;
     sprite.Z = Z;
     sprite.TransformOrigin = TransformOrigin;
     sprite.ZWriteEnable = ZWriteEnable;
     return sprite;
 }
Exemplo n.º 2
0
        public DrawUnit CreateUnit(DrawUnitDef def)
        {
            var bodydef = new BodyDef();
            bodydef.type = def.BodyType;
            bodydef.angle = def.RotateZ;
            bodydef.fixedRotation = def.FixedRotation;
            bodydef.position.X = B2Value(def.X);
            bodydef.position.Y = B2Value(def.Y);
            Body body = _world.CreateBody(bodydef);

            var tex = XNADevicesManager.Instance.ContentManager.Load<Texture2D>(def.TexName);
            Sprite sprite;
            if (def.RepeatX != 0.0f || def.RepeatY != 0.0f)
            {
                var rSprite = new RepeatSprite(tex);
                if (def.RepeatX != 0.0f)
                {
                    rSprite.RepeatX = def.RepeatX;
                }
                if (def.RepeatY != 0.0f)
                {
                    rSprite.RepeatY = def.RepeatY;
                }
                sprite = rSprite;
            }
            else
            {
                sprite = new Sprite(tex);
                sprite.DrawRectangle = def.DrawRectangle;
            }
            sprite.Alpha = def.Alpha;
            sprite.ScaleX = def.ScaleX;
            sprite.ScaleY = def.ScaleY;
            sprite.RotateX = def.RotateX;
            sprite.RotateY = def.RotateY;
            sprite.RotateZ = def.RotateZ;
            sprite.R = def.R;
            sprite.G = def.G;
            sprite.B = def.B;
            sprite.X = def.X;
            sprite.Y = def.Y;
            sprite.Z = def.Z;
            sprite.TransformOrigin = def.TransformOrigin;
            sprite.ZWriteEnable = def.ZWriteEnable;
            var unit = new DrawUnit(sprite, body, this);
            unit.Group = def.Group;
            body.SetUserData(unit);
            return unit;
        }