Loffen
Regular
I am trying to create a 'player' for my tilegame. The sprite function to load the image and create the vertexbuffer looks like this:
And the function that draws the sprite like this:
And during Device Init:
Code:
Public Sub Load(ByVal ImageName As String, ByVal TopLeft As Point, ByVal Width As Integer, ByVal Height As Integer, ByVal ColorKey As Integer)
Dim Vertices() As CustomVertex.PositionTextured
Try
SpriteImage = TextureLoader.FromFile(pDevice, ImageName, Width, Height, D3DX.Default, 0, Format.Unknown, Pool.Default, Filter.Point, Filter.Point, ColorKey)
Catch ex As Exception
MessageBox.Show("Could not load image: " & ImageName & vbCrLf & ex.StackTrace, "Critical Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End
End Try
SpriteBuffer = New VertexBuffer(GetType(CustomVertex.PositionTextured), 4, pDevice, Usage.WriteOnly, CustomVertex.PositionTextured.Format, Pool.Default)
Vertices = SpriteBuffer.Lock(0, 0)
Vertices(0) = New CustomVertex.PositionTextured(TopLeft.X, TopLeft.Y, 1, 0, 0)
Vertices(1) = New CustomVertex.PositionTextured(TopLeft.X + Width, TopLeft.Y, 1, 1, 0)
Vertices(2) = New CustomVertex.PositionTextured(TopLeft.X, TopLeft.Y + Height, 1, 0, 1)
Vertices(3) = New CustomVertex.PositionTextured(TopLeft.X + Width, TopLeft.Y + Height, 1, 1, 1)
SpriteBuffer.Unlock()
End Sub
And the function that draws the sprite like this:
Code:
Public Sub Render()
pDevice.RenderState.AlphaBlendEnable = True
pDevice.VertexFormat = CustomVertex.PositionTextured.Format
pDevice.SetStreamSource(0, SpriteBuffer, 0)
pDevice.SetTexture(0, SpriteImage)
pDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2)
pDevice.RenderState.AlphaBlendEnable = False
End Sub
And during Device Init:
Code:
Device.RenderState.Lighting = False
Device.RenderState.ZBufferEnable = False
Device.RenderState.CullMode = Cull.None
Device.RenderState.AlphaSourceBlend = Blend.SourceAlpha
Device.RenderState.AlphaDestinationBlend = Blend.InvSourceAlpha