Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am trying to create a 'player' for my tilegame. The sprite function to load the image and create the vertexbuffer looks like this:

 

   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:

 

   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:

 

       Device.RenderState.Lighting = False
       Device.RenderState.ZBufferEnable = False
       Device.RenderState.CullMode = Cull.None

       Device.RenderState.AlphaSourceBlend = Blend.SourceAlpha
       Device.RenderState.AlphaDestinationBlend = Blend.InvSourceAlpha

Erutangis a si tahw
Posted

Thsi si what I do:

 

Dim ColorKeyVal As Color = Color.FromArgb(255, 0, 255, 0) 'LimeGreen

 

SpriteImage = TextureLoader.FromFile(dxDevice, ImageName, _32, 32, D3DX.Default, 0, Format.Unknown, Pool.Default, Filter.Point, Filter.Point, ColorKeyVal.ToArgb)

 

I think you'd have to use the ARGB values.

 

-The Pentium Guy

 

My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!)

vbprogramming.8k.com

My Project (Need VB.NET Programmers)

http://workspaces.gotdotnet.com/ResolutionRPG

Posted

Well, figured out, now posting the answear :p..

 

When you init the device do not use:

 

       dxDevice.RenderState.[color=Red]Alpha[/color]SourceBlend = Blend.SourceAlpha
       dxDevice.RenderState.[color=Red]Alpha[/color]DestinationBlend = Blend.InvSourceAlpha

 

But:

 

       dxDevice.RenderState.SourceBlend = Blend.SourceAlpha
       dxDevice.RenderState.DestinationBlend = Blend.InvSourceAlpha

Erutangis a si tahw

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...