/* /// <summary> * /// 创建一个多帧TGraphic实例 * /// </summary> * /// <param name="graphicDevice">显示设备</param> * /// <param name="bitmap">要绘制的图像</param> * /// <param name="pPosition">绘制坐标</param> * /// <param name="pCenter">旋转中心</param> * /// <param name="pFrameCount">总帧数</param> * /// <param name="pFPS">FPS</param> * public TGraphic(Device graphicDevice, Bitmap bitmap, Vector3 pPosition, Vector3 pCenter, * int pFrameCount, int pFPS) * : base(graphicDevice, bitmap, pPosition, 0f, 1f, Color.White, 255, 0) * { * this.frameCount = pFrameCount; * this.currentFrameIndex = 0; * this.mSPerFrame = (int)(1f / pFPS * 1000); * this.msLastFrame = 0; * this.center = pCenter; * this.InitSpriteAction(); * } * * /// <summary> * /// 创建一个单帧TGraphic实例 * /// </summary> * /// <param name="graphicDevice">显示设备</param> * /// <param name="bitmap">要绘制的图像</param> * /// <param name="pPosition">绘制坐标</param> * /// <param name="pCenter">旋转中心</param> * public TGraphic(Device graphicDevice, Bitmap bitmap, Vector3 pPosition, Vector3 pCenter) * : base(graphicDevice, bitmap, pPosition, 0f, 1f, Color.White, 255, 0) * { * this.center = pCenter; * this.frameCount = 1; * this.currentFrameIndex = 0; * this.msLastFrame = 0; * this.mSPerFrame = 16; * this.InitSpriteAction(); * }*/ private static Vector2 Getorigin(Texture2D texture, ElementOrigin origin) { var id = (int)origin; float x = (float)(id % 3) / 2 * texture.Width; float y = (float)(id - id % 3) / 6 * texture.Height; return(new Vector2(x, y)); }
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(); }
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(); }
/* /// <summary> /// 创建一个多帧TGraphic实例 /// </summary> /// <param name="graphicDevice">显示设备</param> /// <param name="bitmap">要绘制的图像</param> /// <param name="pPosition">绘制坐标</param> /// <param name="pCenter">旋转中心</param> /// <param name="pFrameCount">总帧数</param> /// <param name="pFPS">FPS</param> public TGraphic(Device graphicDevice, Bitmap bitmap, Vector3 pPosition, Vector3 pCenter, int pFrameCount, int pFPS) : base(graphicDevice, bitmap, pPosition, 0f, 1f, Color.White, 255, 0) { this.frameCount = pFrameCount; this.currentFrameIndex = 0; this.mSPerFrame = (int)(1f / pFPS * 1000); this.msLastFrame = 0; this.center = pCenter; this.InitSpriteAction(); } /// <summary> /// 创建一个单帧TGraphic实例 /// </summary> /// <param name="graphicDevice">显示设备</param> /// <param name="bitmap">要绘制的图像</param> /// <param name="pPosition">绘制坐标</param> /// <param name="pCenter">旋转中心</param> public TGraphic(Device graphicDevice, Bitmap bitmap, Vector3 pPosition, Vector3 pCenter) : base(graphicDevice, bitmap, pPosition, 0f, 1f, Color.White, 255, 0) { this.center = pCenter; this.frameCount = 1; this.currentFrameIndex = 0; this.msLastFrame = 0; this.mSPerFrame = 16; this.InitSpriteAction(); }*/ private Vector2 Getorigin(Texture2D texture, ElementOrigin Origin) { int id = (int)Origin; float x = (float)(id % 3) / 2 * texture.Width; float y = (float)(id - id % 3) / 6 * texture.Height; return new Vector2(x, y); }
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(); }