コード例 #1
0
ファイル: TGraphic.cs プロジェクト: NitroP/OSUplayer
 public TGraphic(Device graphicDevice, SBelement Element, string Location, int layerdelta)
     : base()
 {
     switch (Element.Type)
     {
         case ElementType.Sprite:
             {
                 if (File.Exists(Path.Combine(Location, Element.Path)))
                 {
                     using (FileStream s = new FileStream(Path.Combine(Location, Element.Path), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                     {
                         this.texturearray = new Texture2D[1] { Texture2D.FromFile(graphicDevice, s) };
                     }
                 }
                 else
                 {
                     this.texturearray = new Texture2D[1] { new Texture2D(graphicDevice, 1, 1, 0, 0, SurfaceFormat.Bgr32) };
                 }
                 this.frameCount = 1;
                 this.currentFrameIndex = 0;
                 this.msLastFrame = 0;
                 this.mSPerFrame = 16;
                 this.position = new Vector2(Element.x, Element.y);
                 this.origin = Getorigin(this.texturearray[0], Element.Origin);
                 break;
             }
         case ElementType.Animation:
             {
                 string prefix = Path.Combine(Location, Element.Path);
                 string ext = prefix.Substring(prefix.LastIndexOf(".") + 1);
                 prefix = prefix.Substring(0, prefix.LastIndexOf("."));
                 texturearray = new Texture2D[Element.FrameCount];
                 for (int i = 0; i < Element.FrameCount; i++)
                 {
                     if (File.Exists(prefix + i.ToString() + "." + ext))
                     {
                         using (FileStream s = new FileStream(prefix + i.ToString() + "." + ext, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                         {
                             this.texturearray[i] = Texture2D.FromFile(graphicDevice, s);
                         }
                     }
                     else
                     {
                         this.texturearray[i] = new Texture2D(graphicDevice, 1, 1, 0, 0, SurfaceFormat.Bgr32);
                     }
                 }
                 this.frameCount = Element.FrameCount;
                 this.mSPerFrame = Element.Framedelay;
                 this.Loop = Element.Looptype;
                 this.currentFrameIndex = 0;
                 this.msLastFrame = 0;
                 this.position = new Vector2(Element.x, Element.y);
                 //this.texture = texturearray[0];
                 this.origin = Getorigin(this.texturearray[0], Element.Origin);
                 break;
             }
         default:
             throw (new FormatException("Failed to resolve .osb file"));
     }
     this.Origin = Element.Origin;
     this.color = Color.White;
     this.alpha = 0;
     this.parameter = 0;
     this.rotate = 0f;
     if (Element.Layers == ElementLayer.Background) { this.layer = 0.9f - layerdelta * 0.000001f; } else { this.layer = 0.5f - layerdelta * 0.000001f; }
     this.scale = new Vector2(1f, 1f);
     //  this.InitSpriteAction();
 }
コード例 #2
0
ファイル: TGraphic.cs プロジェクト: xc0102/OSUplayer
 public TGraphic(SBelement element, Texture2D[] file)
 {
     switch (element.Type)
     {
         case ElementType.Sprite:
         {
             Texturearray = file;
             FrameCount = 1;
             CurrentFrameIndex = 0;
             _msLastFrame = 0;
             _mSPerFrame = 16;
             Position = new Vector2(element.X0, element.Y0);
             Origin = Getorigin(Texturearray[0], element.Origin);
             break;
         }
         case ElementType.Animation:
         {
             Texturearray = file;
             FrameCount = element.FrameCount;
             _mSPerFrame = element.Framedelay;
             _loop = element.Looptype;
             CurrentFrameIndex = 0;
             _msLastFrame = 0;
             Position = new Vector2(element.X0, element.Y0);
             //this.texture = texturearray[0];
             Origin = Getorigin(Texturearray[0], element.Origin);
             break;
         }
         default:
             throw (new FormatException("Failed to resolve .osb file"));
     }
     _origin = element.Origin;
     Color = Color.White;
     Alpha = 0;
     Parameter = 0;
     Rotate = 0f;
     if (element.Layers == ElementLayer.Background)
     {
         Layer = 0.9f - element.Z*0.000001f;
     }
     else
     {
         Layer = 0.5f - element.Z*0.000001f;
     }
     Scale = new Vector2(1f, 1f);
     //  this.InitSpriteAction();
 }