public void DrawSprite() { if (vbuffer == null) { vbuffer = new VertexBuffer(Resource.device, sizeof(float) * 20, Usage.WriteOnly, VertexFormat.None, Pool.Managed); } float hw = Width / 2; float hh = Height / 2; TexRect rc = getRect(); vbuffer.Lock(0, 0, LockFlags.None).WriteRange(new[] { -hw, -hh, 0.0f, rc.Left, rc.Bottom, //0.0f, 1.0f, -hw, hh, 0.0f, rc.Left, rc.Top, //0.0f, 0.0f, hw, hh, 0.0f, rc.Right, rc.Top, //1.0f, 0.0f, hw, -hh, 0.0f, rc.Right, rc.Bottom, //1.0f, 1.0f, }); vbuffer.Unlock(); Device device = Resource.device; device.SetRenderState(RenderState.Lighting, false); device.SetRenderState(RenderState.AlphaBlendEnable, true); device.SetRenderState(RenderState.SourceBlend, 5); device.SetRenderState(RenderState.DestinationBlend, 6); device.SetTexture(0, texture); device.VertexFormat = VertexFormat.Position | VertexFormat.Texture1; device.SetStreamSource(0, vbuffer, 0, sizeof(float) * 5); //device.SetRenderState(RenderState.AlphaBlendEnable, true); device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2); device.SetTexture(0, null); }
public Rectangle(TexRect texRect, Texture texture, float width, float height, float angleOffset = 0) { this.texRect = texRect; this.texture = texture; this.width = width; this.height = height; this.angleOffset = angleOffset; }
public DemoEnemy() { Speed = 50; uvWidth = 0.09375f; uvHeight = 0.0625f; zoomrate = 200; texture = Resource.textures["enemy1"]; IdleUVs = new TexRect[] { new TexRect(0.09375f * 0, 0, 0.09375f * 1, 0.0625f), new TexRect(0.09375f * 1, 0, 0.09375f * 2, 0.0625f), new TexRect(0.09375f * 2, 0, 0.09375f * 3, 0.0625f), new TexRect(0.09375f * 3, 0, 0.09375f * 4, 0.0625f), }; }
public Reimu() { texture = Resource.textures["reimu"]; uvWidth = 0.125f; uvHeight = 0.1875f; zoomrate = 100; IdleUVs = new TexRect[] { new TexRect(0.125f * 0, 0, 0.125f * 1, 0.1875f), new TexRect(0.125f * 1, 0, 0.125f * 2, 0.1875f), new TexRect(0.125f * 2, 0, 0.125f * 3, 0.1875f), new TexRect(0.125f * 3, 0, 0.125f * 4, 0.1875f), new TexRect(0.125f * 4, 0, 0.125f * 5, 0.1875f), new TexRect(0.125f * 5, 0, 0.125f * 6, 0.1875f), new TexRect(0.125f * 6, 0, 0.125f * 7, 0.1875f), new TexRect(0.125f * 7, 0, 0.125f * 8, 0.1875f), }; Idle2LeftUVs = new TexRect[] { new TexRect(0.125f * 0, 0.1875f, 0.125f * 1, 0.375f), new TexRect(0.125f * 1, 0.1875f, 0.125f * 2, 0.375f), new TexRect(0.125f * 2, 0.1875f, 0.125f * 3, 0.375f), new TexRect(0.125f * 3, 0.1875f, 0.125f * 4, 0.375f), }; Idle2RightUVs = new TexRect[] { new TexRect(0.125f * 0, 0.375f, 0.125f * 1, 0.5625f), new TexRect(0.125f * 1, 0.375f, 0.125f * 2, 0.5625f), new TexRect(0.125f * 2, 0.375f, 0.125f * 3, 0.5625f), new TexRect(0.125f * 3, 0.375f, 0.125f * 4, 0.5625f), }; LeftUVs = new TexRect[] { new TexRect(0.125f * 4, 0.1875f, 0.125f * 5, 0.375f), new TexRect(0.125f * 5, 0.1875f, 0.125f * 6, 0.375f), new TexRect(0.125f * 6, 0.1875f, 0.125f * 7, 0.375f), new TexRect(0.125f * 7, 0.1875f, 0.125f * 8, 0.375f), }; RightUVs = new TexRect[] { new TexRect(0.125f * 4, 0.375f, 0.125f * 5, 0.5625f), new TexRect(0.125f * 5, 0.375f, 0.125f * 6, 0.5625f), new TexRect(0.125f * 6, 0.375f, 0.125f * 7, 0.5625f), new TexRect(0.125f * 7, 0.375f, 0.125f * 8, 0.5625f), }; }
public void Draw(Vector3 position, float angle) { if (vbuffer == null) { vbuffer = new VertexBuffer(Resource.device, sizeof(float) * 20, Usage.WriteOnly, VertexFormat.None, Pool.Managed); } float hw = width / 2; float hh = height / 2; TexRect rc = texRect; vbuffer.Lock(0, 0, LockFlags.None).WriteRange(new[] { -hw, -hh, 0.0f, rc.Left, rc.Bottom, //0.0f, 1.0f, -hw, hh, 0.0f, rc.Left, rc.Top, //0.0f, 0.0f, hw, hh, 0.0f, rc.Right, rc.Top, //1.0f, 0.0f, hw, -hh, 0.0f, rc.Right, rc.Bottom, //1.0f, 1.0f, }); vbuffer.Unlock(); Device device = Resource.device; device.SetRenderState(RenderState.Lighting, false); device.SetRenderState(RenderState.AlphaBlendEnable, true); device.SetRenderState(RenderState.SourceBlend, 5); device.SetRenderState(RenderState.DestinationBlend, 6); device.SetTexture(0, texture); device.VertexFormat = VertexFormat.Position | VertexFormat.Texture1; device.SetStreamSource(0, vbuffer, 0, sizeof(float) * 5); //device.SetRenderState(RenderState.AlphaBlendEnable, true); Matrix matWorld = Matrix.Translation(position); Matrix matRotation = Matrix.RotationZ((float)(angle + angleOffset * System.Math.PI / 180)); device.SetTransform(TransformState.World, matRotation * matWorld); device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2); device.SetTexture(0, null); }