Results 1 to 6 of 6

Thread: XNA to DirectX [RPG] Sprite problem

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2014
    Posts
    53

    Lightbulb XNA to DirectX [RPG] Sprite problem

    Hello poeple!

    I dropped XNA for directx3d,directx,directx3dx (directx.....)

    So i converted most of my xna code to directx by using this tutorial and this tutorial

    Pastebin:
    My code dx3dengine

    My code DXsprite

    My code GameEngine

    My OLD XNA CODE

    I didnt change anything else but loading the sprites to the "GameForm"
    Tinypic(screenshots)
    now it looks like (DirectX)
    and it should look like (XNA)

    Does someone knows whats wrong? by looking at my code, Btw i copied the BitmapToTexture Sub from XNA

    MANY MANY THANKS! if you can help me out!

    Omg i need this LMAO ice cream!

  2. #2

    Thread Starter
    Member
    Join Date
    Mar 2014
    Posts
    53

    Re: XNA to DirectX [RPG] Sprite problem

    Got this to work! but how do i use it in another thread? cus when i run the rendering in another thread it doesnt draw at all

    something to do with invoke?

  3. #3
    Computer Science BS Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,339

    Re: XNA to DirectX [RPG] Sprite problem

    Hey SwordEdge, I betcha miss me from the last thread

    Next time please post in the Games and Graphics section though. All the game related issues go in that section. Only standard VB questions go in the VB.Net section.

    And I know you might be new to DX programming, but if those tutorials didn't tell you, be sure your .NET Framework is set for 3.5, and the CPU target is x86. VB.Net uses DirectX9 sadly since DX10 and DX11 is targeted towards C++. And since DX9 is an older but still widely used DX, it must be set to those settings in your project for it to work.

    I don't know why you are multithreading but its not needed at all unless you are making a triple A title and rendering millions of polygons in a 3D world. So you don't need to multithread for simple 2D RPG's. Matter of fact, I have an algorithm to make the worlds as large as you want with zero slowdown. No multithreading used.

    Another thing is that you are making the initialization unnecessarily complex, and it doesn't need to be wrapped in a class at all because it already is a class. Why wrap a class within a class? When you dispose of it for example, you end up disposing the class that ends up disposing the device. See what I mean, it ends up becoming a hierarchy of disposals. And thankfully you got a DirectX guru here to help get you a proper DX initialization.

    Also you don't need to call it 3D if your RPG is going to be 2D. Yes you are using Direct3D for 2D, but since its being initialized for 2D, you can call it DX2DEngine. Otherwise if you were to refer back to your project months or years down the road you would be asking yourself "Did I make it 2D or 3D?" Or even worse...if someone looked at your code and wasn't too sure how you initialized it, whether its 2D or 3D. Anyways, initialization is as simple as this:

    vb.net Code:
    1. Option Explicit On
    2. Option Strict On
    3.  
    4. Imports Microsoft.DirectX
    5. Imports Microsoft.DirectX.Direct3D
    6.  
    7. Public Class frmMain
    8.  
    9.     Private Device As Device
    10.     Private Display_Mode As DisplayMode
    11.     Private Screen As PresentParameters = New PresentParameters
    12.  
    13.     Private Fullscreen_Enabled As Boolean
    14.     Private Running As Boolean
    15.  
    16.     Private Sub DirectX_Initialize()
    17.  
    18.         If Fullscreen_Enabled = True Then
    19.             Display_Mode.Width = 1920
    20.             Display_Mode.Height = 1080
    21.             Display_Mode.Format = Format.A8B8G8R8
    22.             Screen.Windowed = False
    23.             Screen.BackBufferCount = 1
    24.             Screen.BackBufferWidth = Display_Mode.Width
    25.             Screen.BackBufferHeight = Display_Mode.Height
    26.         Else
    27.             Screen.Windowed = True
    28.         End If
    29.  
    30.         Screen.SwapEffect = SwapEffect.Copy
    31.         Screen.BackBufferFormat = Display_Mode.Format
    32.         Device = New Device(0, DeviceType.Hardware, Me.Handle, CreateFlags.SoftwareVertexProcessing, Screen)
    33.  
    34.     End Sub
    35.  
    36.     Private Sub Render()
    37.  
    38.         Device.Clear(ClearFlags.Target, Color.FromArgb(0, 0, 0), 1.0, 0)
    39.         Device.BeginScene()
    40.         'Rendering code goes here
    41.         Device.EndScene()
    42.         Device.Present()
    43.  
    44.     End Sub
    45.  
    46.     Private Sub Game_Loop()
    47.  
    48.         Do While Running = True
    49.             Render()
    50.             Application.DoEvents()
    51.         Loop
    52.  
    53.     End Sub
    54.  
    55.     Private Sub Main()
    56.  
    57.         If MessageBox.Show("Click Yes to go to fullscreen (Recommended)", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
    58.             Fullscreen_Enabled = True
    59.         End If
    60.  
    61.         With Me
    62.             .Show()
    63.             .Width = 330
    64.             .Height = 250
    65.             .SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.Opaque, True)
    66.             .Text = "DirectX Tutorial"
    67.             If Fullscreen_Enabled = True Then .FormBorderStyle = Windows.Forms.FormBorderStyle.None
    68.         End With
    69.  
    70.         DirectX_Initialize()
    71.         Running = True
    72.  
    73.     End Sub
    74.  
    75.     Private Sub Shutdown()
    76.  
    77.         Running = False
    78.         Device.Dispose()
    79.         Application.Exit()
    80.  
    81.     End Sub
    82.  
    83.     Private Sub frmMain_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    84.  
    85.         If e.KeyCode = Keys.Escape Then Shutdown()
    86.  
    87.     End Sub
    88.  
    89.     Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    90.  
    91.         Main()
    92.  
    93.     End Sub
    94.  
    95.     Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    96.  
    97.         Shutdown()
    98.  
    99.     End Sub
    100.  
    101.     Private Sub frmMain_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    102.  
    103.         Game_Loop()
    104.  
    105.     End Sub
    106.  
    107.     Private Sub frmMain_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
    108.  
    109.         If Fullscreen_Enabled = False Then
    110.             Running = False
    111.             Device.Reset(Screen)
    112.             Application.DoEvents()
    113.             Running = True
    114.         End If
    115.  
    116.     End Sub
    117.  
    118. End Class

    This allows you to enter either fullscreen or windowed mode. With this, a simple way to draw a polygon would be to do this:

    vb.net Code:
    1. Option Explicit On
    2. Option Strict On
    3.  
    4. Imports Microsoft.DirectX
    5. Imports Microsoft.DirectX.Direct3D
    6.  
    7. Public Class frmMain
    8.  
    9.     Private Device As Device
    10.     Private Display_Mode As DisplayMode
    11.     Private Screen As PresentParameters = New PresentParameters
    12.  
    13.     Private Fullscreen_Enabled As Boolean
    14.     Private Running As Boolean = True
    15.  
    16.     Private Vertex_List As CustomVertex.TransformedColored() = New CustomVertex.TransformedColored(3) {}
    17.  
    18.     Private Sub DirectX_Initialize()
    19.  
    20.         If Fullscreen_Enabled = True Then
    21.             Display_Mode.Width = 1920
    22.             Display_Mode.Height = 1080
    23.             Display_Mode.Format = Format.A8B8G8R8
    24.             Screen.Windowed = False
    25.             Screen.BackBufferCount = 1
    26.             Screen.BackBufferWidth = Display_Mode.Width
    27.             Screen.BackBufferHeight = Display_Mode.Height
    28.         Else
    29.             Screen.Windowed = True
    30.         End If
    31.         Screen.SwapEffect = SwapEffect.Copy
    32.         Screen.BackBufferFormat = Display_Mode.Format
    33.         Device = New Device(0, DeviceType.Hardware, Me.Handle, CreateFlags.SoftwareVertexProcessing, Screen)
    34.  
    35.     End Sub
    36.  
    37.     Private Function Create_Custom_Vertex(ByVal X As Single, ByVal Y As Single, ByVal Z As Single, ByVal RHW As Single, ByVal Color As Integer) As CustomVertex.TransformedColored
    38.  
    39.         Dim Vertex As CustomVertex.TransformedColored = New CustomVertex.TransformedColored
    40.  
    41.         Vertex.Position = New Vector4(X, Y, Z, 1)
    42.         Vertex.Rhw = RHW
    43.         Vertex.Color = Color
    44.  
    45.         Return Vertex
    46.  
    47.     End Function
    48.  
    49.     Private Sub Create_Polygon()
    50.  
    51.         Vertex_List(0) = Create_Custom_Vertex(0, 0, 0, 1, Color.FromArgb(255, 255, 255).ToArgb)
    52.         Vertex_List(1) = Create_Custom_Vertex(100, 0, 0, 1, Color.FromArgb(255, 255, 255).ToArgb)
    53.         Vertex_List(2) = Create_Custom_Vertex(0, 100, 0, 1, Color.FromArgb(255, 255, 255).ToArgb)
    54.         Vertex_List(3) = Create_Custom_Vertex(100, 100, 0, 1, Color.FromArgb(255, 255, 255).ToArgb)
    55.  
    56.     End Sub
    57.  
    58.     Private Sub Draw_Polygon()
    59.  
    60.         Device.VertexFormat = CustomVertex.TransformedColored.Format
    61.         Device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, Vertex_List)
    62.  
    63.     End Sub
    64.  
    65.     Private Sub Render()
    66.  
    67.         Device.Clear(ClearFlags.Target, Color.FromArgb(0, 0, 0), 1.0#, 0)
    68.         Device.BeginScene()
    69.         'Rendering code goes here
    70.         Create_Polygon()
    71.         Draw_Polygon()
    72.         Device.EndScene()
    73.         Device.Present()
    74.  
    75.     End Sub
    76.  
    77.     Private Sub Game_Loop()
    78.  
    79.         Do While Running = True
    80.             Render()
    81.             Application.DoEvents()
    82.         Loop
    83.  
    84.     End Sub
    85.  
    86.     Private Sub Main()
    87.  
    88.         If MessageBox.Show("Click Yes to go to fullscreen (Recommended)", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
    89.             Fullscreen_Enabled = True
    90.         End If
    91.  
    92.         With Me
    93.             .Show()
    94.             .Width = 330
    95.             .Height = 250
    96.             .SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.Opaque, True)
    97.             .Text = "DirectX Tutorial"
    98.             If Fullscreen_Enabled = True Then .FormBorderStyle = Windows.Forms.FormBorderStyle.None
    99.         End With
    100.  
    101.         DirectX_Initialize()
    102.         Running = True
    103.  
    104.     End Sub
    105.  
    106.     Private Sub Shutdown()
    107.  
    108.         Running = False
    109.         Device = Nothing
    110.         Application.Exit()
    111.  
    112.     End Sub
    113.  
    114.     Private Sub frmMain_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    115.  
    116.         If e.KeyCode = Keys.Escape Then Shutdown()
    117.  
    118.     End Sub
    119.  
    120.     Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    121.  
    122.         Main()
    123.  
    124.     End Sub
    125.  
    126.     Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    127.  
    128.         Shutdown()
    129.  
    130.     End Sub
    131.  
    132.     Private Sub frmMain_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    133.  
    134.         Game_Loop()
    135.  
    136.     End Sub
    137.  
    138.     Private Sub frmMain_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
    139.  
    140.         If Fullscreen_Enabled = False Then
    141.             Running = False
    142.             Device.Reset(Screen)
    143.             Application.DoEvents()
    144.             Running = True
    145.         End If
    146.  
    147.     End Sub
    148.  
    149. End Class

    Continued next post.....

  4. #4
    Computer Science BS Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,339

    Re: XNA to DirectX [RPG] Sprite problem

    Continued from last post:

    To texturemap the polygon with an image loaded from file you would do this:

    vb.net Code:
    1. Option Explicit On
    2. Option Strict On
    3.  
    4. Imports Microsoft.DirectX
    5. Imports Microsoft.DirectX.Direct3D
    6.  
    7. Public Class frmMain
    8.  
    9.     Private Device As Device
    10.     Private Display_Mode As DisplayMode
    11.     Private Screen As PresentParameters = New PresentParameters
    12.  
    13.     Private Fullscreen_Enabled As Boolean
    14.     Private Running As Boolean = True
    15.  
    16.     Private Vertex_List As CustomVertex.TransformedColoredTextured() = New CustomVertex.TransformedColoredTextured(0 To 3) {}
    17.     Private Texture As Texture
    18.  
    19.     Private Sub DirectX_Initialize()
    20.  
    21.         If Fullscreen_Enabled = True Then
    22.             Display_Mode.Width = 1920
    23.             Display_Mode.Height = 1080
    24.             Display_Mode.Format = Format.A8B8G8R8
    25.             Screen.Windowed = False
    26.             Screen.BackBufferCount = 1
    27.             Screen.BackBufferWidth = Display_Mode.Width
    28.             Screen.BackBufferHeight = Display_Mode.Height
    29.         Else
    30.             Screen.Windowed = True
    31.         End If
    32.  
    33.         Screen.SwapEffect = SwapEffect.Copy
    34.         Screen.BackBufferFormat = Display_Mode.Format
    35.  
    36.         Device = New Device(0, DeviceType.Hardware, Me.Handle, CreateFlags.SoftwareVertexProcessing, Screen)
    37.  
    38.     End Sub
    39.  
    40.     Private Function Create_Custom_Vertex(ByVal X As Single, ByVal Y As Single, ByVal Z As Single, ByVal Color As Integer, ByVal TU As Integer, ByVal TV As Integer) As CustomVertex.TransformedColoredTextured
    41.  
    42.         Dim Vertex As CustomVertex.TransformedColoredTextured = New CustomVertex.TransformedColoredTextured
    43.  
    44.         Vertex.Position = New Vector4(X, Y, Z, 1)
    45.         Vertex.Color = Color
    46.         Vertex.Tu = TU
    47.         Vertex.Tv = TV
    48.  
    49.         Return Vertex
    50.  
    51.     End Function
    52.  
    53.     Private Sub Create_Polygon()
    54.  
    55.         Vertex_List(0) = Create_Custom_Vertex(0, 0, 0, System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb, 0, 0)
    56.         Vertex_List(1) = Create_Custom_Vertex(100, 0, 0, System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb, 1, 0)
    57.         Vertex_List(2) = Create_Custom_Vertex(0, 100, 0, System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb, 0, 1)
    58.         Vertex_List(3) = Create_Custom_Vertex(100, 100, 0, System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb, 1, 1)
    59.  
    60.     End Sub
    61.  
    62.     Private Sub Draw_Polygon()
    63.  
    64.         Device.VertexFormat = CustomVertex.TransformedColoredTextured.Format
    65.         Device.SetTexture(0, Texture)
    66.         Device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, Vertex_List)
    67.  
    68.     End Sub
    69.  
    70.     Private Sub Load_Texture(ByRef Texture As Texture, ByVal Filepath As String, ByVal Transparency_Color As Integer)
    71.  
    72.         Texture = TextureLoader.FromFile(Device, Filepath, 512, 512, 1, Usage.None, Format.A8B8G8R8, Pool.Managed, Filter.Point, Filter.Point, Transparency_Color)
    73.  
    74.     End Sub
    75.  
    76.     Private Sub Render()
    77.  
    78.         Device.Clear(ClearFlags.Target, Color.Black, 1.0, 0)
    79.         Device.BeginScene()
    80.         'Rendering code goes here.
    81.         Create_Polygon()
    82.         Draw_Polygon()
    83.         Device.EndScene()
    84.         Device.Present()
    85.  
    86.     End Sub
    87.  
    88.     Private Sub Game_Loop()
    89.  
    90.         Do While Running = True
    91.             Render()
    92.             Application.DoEvents()
    93.         Loop
    94.  
    95.     End Sub
    96.  
    97.     Private Sub Main()
    98.  
    99.         If MessageBox.Show("Click Yes to go to full screen (Recommended)", "", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = DialogResult.Yes Then
    100.             Fullscreen_Enabled = True
    101.         End If
    102.  
    103.         With Me
    104.             .Show()
    105.             .Width = 330
    106.             .Height = 250
    107.             .SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.Opaque, True)
    108.             .Text = "DirectX Tutorial"
    109.             If Fullscreen_Enabled = True Then .FormBorderStyle = Windows.Forms.FormBorderStyle.None
    110.         End With
    111.  
    112.         DirectX_Initialize()
    113.         Load_Texture(Texture, Application.StartupPath() & "\texture.jpg", System.Drawing.Color.FromArgb(0, 0, 0, 0).ToArgb)
    114.         Running = True
    115.  
    116.     End Sub
    117.  
    118.     Private Sub Shutdown()
    119.  
    120.         Running = False
    121.         Texture.Dispose()
    122.         Texture = Nothing
    123.         Device = Nothing
    124.         Application.Exit()
    125.  
    126.     End Sub
    127.  
    128.  
    129.     Private Sub frmMain_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    130.  
    131.         If e.KeyCode = Keys.Escape Then Shutdown()
    132.  
    133.     End Sub
    134.  
    135.     Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    136.  
    137.         Main()
    138.  
    139.     End Sub
    140.  
    141.     Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    142.  
    143.         Shutdown()
    144.  
    145.     End Sub
    146.  
    147.     Private Sub frmMain_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    148.  
    149.         Game_Loop()
    150.  
    151.     End Sub
    152.  
    153.     Private Sub frmMain_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
    154.  
    155.         If Fullscreen_Enabled = False Then
    156.             Running = False
    157.             Device.Reset(Screen)
    158.             Application.DoEvents()
    159.             Running = True
    160.         End If
    161.  
    162.     End Sub
    163. End Class

    To make the texturemapped polygon transparent so the backcolor is removed, and the alpha values can be controlled to fade in/out the sprites:

    vb.net Code:
    1. Option Explicit On
    2. Option Strict On
    3.  
    4. Imports Microsoft.DirectX
    5. Imports Microsoft.DirectX.Direct3D
    6.  
    7. Public Class frmMain
    8.  
    9.     Private Device As Device
    10.     Private Display_Mode As DisplayMode
    11.     Private Screen As PresentParameters = New PresentParameters
    12.  
    13.     Private Fullscreen_Enabled As Boolean
    14.     Private Running As Boolean = True
    15.  
    16.     Private Vertex_List As CustomVertex.TransformedColoredTextured() = New CustomVertex.TransformedColoredTextured(0 To 3) {} 'create an array of vertices
    17.     Private Texture As Texture
    18.  
    19.     Private Function Create_Custom_Vertex(ByVal X As Single, ByVal Y As Single, ByVal Z As Single, ByVal Color As Integer, ByVal TU As Integer, ByVal TV As Integer) As CustomVertex.TransformedColoredTextured
    20.  
    21.         Dim Vertex As CustomVertex.TransformedColoredTextured
    22.  
    23.         Vertex.Position = New Vector4(X, Y, Z, 1)
    24.         Vertex.Color = Color
    25.         Vertex.Tu = TU
    26.         Vertex.Tv = TV
    27.  
    28.         Return Vertex
    29.  
    30.     End Function
    31.  
    32.     Private Sub DirectX_Initialize()
    33.  
    34.         If Fullscreen_Enabled = True Then
    35.             Display_Mode.Width = 1920
    36.             Display_Mode.Height = 1080
    37.             Display_Mode.Format = Format.A8B8G8R8
    38.             Screen.Windowed = False
    39.             Screen.BackBufferCount = 1
    40.             Screen.BackBufferWidth = Display_Mode.Width
    41.             Screen.BackBufferHeight = Display_Mode.Height
    42.         Else
    43.             Screen.Windowed = True
    44.         End If
    45.  
    46.         Screen.SwapEffect = SwapEffect.Copy
    47.         Screen.BackBufferFormat = Display_Mode.Format
    48.  
    49.         Device = New Device(0, DeviceType.Hardware, Me.Handle, CreateFlags.SoftwareVertexProcessing, Screen)
    50.  
    51.         Device.SetRenderState(RenderStates.AlphaBlendEnable, True)
    52.  
    53.         Device.SetTextureStageState(0, TextureStageStates.ColorOperation, TextureOperation.Modulate)
    54.         Device.SetTextureStageState(0, TextureStageStates.ColorArgument1, TextureArgument.TextureColor)
    55.         Device.SetTextureStageState(0, TextureStageStates.ColorArgument2, TextureArgument.Diffuse)
    56.  
    57.         Device.SetTextureStageState(0, TextureStageStates.AlphaOperation, TextureOperation.Modulate)
    58.         Device.SetTextureStageState(0, TextureStageStates.AlphaArgument1, TextureArgument.TextureColor)
    59.         Device.SetTextureStageState(0, TextureStageStates.AlphaArgument2, TextureArgument.Diffuse)
    60.  
    61.         Device.SetRenderState(RenderStates.SourceBlend, Blend.SourceAlpha)
    62.         Device.SetRenderState(RenderStates.DestinationBlend, Blend.InvSourceAlpha)
    63.         Device.SetRenderState(RenderStates.BlendOperation, TextureOperation.Add)
    64.  
    65.         Device.SetSamplerState(0, SamplerStageStates.MinFilter, TextureFilter.Point)
    66.         Device.SetSamplerState(0, SamplerStageStates.MagFilter, TextureFilter.Point)
    67.  
    68.     End Sub
    69.  
    70.     Private Sub Create_Polygon()
    71.  
    72.         Vertex_List(0) = Create_Custom_Vertex(0, 0, 0, System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb, 0, 0)
    73.         Vertex_List(1) = Create_Custom_Vertex(100, 0, 0, System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb, 1, 0)
    74.         Vertex_List(2) = Create_Custom_Vertex(0, 100, 0, System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb, 0, 1)
    75.         Vertex_List(3) = Create_Custom_Vertex(100, 100, 0, System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb, 1, 1)
    76.  
    77.     End Sub
    78.  
    79.     Private Sub Draw_Polygon()
    80.  
    81.         Device.VertexFormat = CustomVertex.TransformedColoredTextured.Format
    82.         Device.SetTexture(0, Texture)
    83.         Device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, Vertex_List)
    84.  
    85.     End Sub
    86.  
    87.     Private Sub Load_Texture(ByRef Texture As Texture, ByVal Filepath As String, ByVal Transparency_Color As Integer)
    88.  
    89.         Texture = TextureLoader.FromFile(Device, Filepath, 512, 512, 1, Usage.None, Format.A8B8G8R8, Pool.Managed, Filter.Point, Filter.Point, Transparency_Color)
    90.  
    91.     End Sub
    92.  
    93.     Private Sub Render()
    94.  
    95.         Device.Clear(ClearFlags.Target, System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb, 1.0, 0)
    96.         Device.BeginScene()
    97.         'Rendering code goes here.
    98.         Create_Polygon()
    99.         Draw_Polygon()
    100.         Device.EndScene()
    101.         Device.Present()
    102.         Application.DoEvents()
    103.  
    104.     End Sub
    105.  
    106.     Private Sub Game_Loop()
    107.  
    108.         Do While Running = True
    109.             Render()
    110.         Loop
    111.  
    112.     End Sub
    113.  
    114.     Private Sub Main()
    115.  
    116.         If MessageBox.Show("Click Yes to go to full screen (Recommended)", "", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = DialogResult.Yes Then
    117.             Fullscreen_Enabled = True
    118.         End If
    119.  
    120.         With Me
    121.             .Show()
    122.             .Width = 330
    123.             .Height = 250
    124.             .SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.Opaque, True) 'Do not draw forms background
    125.             .Text = "DirectX Tutorial"
    126.             If Fullscreen_Enabled = True Then .FormBorderStyle = Windows.Forms.FormBorderStyle.None
    127.         End With
    128.  
    129.         DirectX_Initialize()
    130.         Load_Texture(Texture, Application.StartupPath() & "\Sprite1.png", System.Drawing.Color.FromArgb(255, 0, 0, 0).ToArgb)
    131.         Running = True
    132.  
    133.     End Sub
    134.  
    135.     Private Sub Shutdown()
    136.  
    137.         Running = False
    138.         Texture = Nothing
    139.         Device = Nothing
    140.         Application.Exit()
    141.  
    142.     End Sub
    143.  
    144.  
    145.     Private Sub frmMain_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    146.  
    147.         If e.KeyCode = Keys.Escape Then Shutdown()
    148.  
    149.     End Sub
    150.  
    151.     Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    152.  
    153.         Main()
    154.  
    155.     End Sub
    156.  
    157.     Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    158.  
    159.         Shutdown()
    160.  
    161.     End Sub
    162.  
    163.     Private Sub frmMain_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    164.  
    165.         Game_Loop()
    166.  
    167.     End Sub
    168.  
    169.     Private Sub frmMain_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
    170.  
    171.         If Fullscreen_Enabled = False Then
    172.             Running = False
    173.             'Resets everything
    174.             '---------------------------------------------
    175.             Device.Reset(Screen)
    176.             Device.SetRenderState(RenderStates.AlphaBlendEnable, True)
    177.  
    178.             Device.SetTextureStageState(0, TextureStageStates.ColorOperation, TextureOperation.Modulate)
    179.             Device.SetTextureStageState(0, TextureStageStates.ColorArgument1, TextureArgument.TextureColor)
    180.             Device.SetTextureStageState(0, TextureStageStates.ColorArgument2, TextureArgument.Diffuse)
    181.  
    182.             Device.SetTextureStageState(0, TextureStageStates.AlphaOperation, TextureOperation.Modulate)
    183.             Device.SetTextureStageState(0, TextureStageStates.AlphaArgument1, TextureArgument.TextureColor)
    184.             Device.SetTextureStageState(0, TextureStageStates.AlphaArgument2, TextureArgument.Diffuse)
    185.  
    186.             Device.SetRenderState(RenderStates.SourceBlend, Blend.SourceAlpha)
    187.             Device.SetRenderState(RenderStates.DestinationBlend, Blend.InvSourceAlpha)
    188.             Device.SetRenderState(RenderStates.BlendOperation, TextureOperation.Add)
    189.  
    190.             Device.SetSamplerState(0, SamplerStageStates.MinFilter, TextureFilter.Point)
    191.             Device.SetSamplerState(0, SamplerStageStates.MagFilter, TextureFilter.Point)
    192.             '---------------------------------------------
    193.             Application.DoEvents()
    194.             Running = True
    195.         End If
    196.  
    197.     End Sub
    198. End Class

    Continued next post...

  5. #5
    Computer Science BS Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,339

    Re: XNA to DirectX [RPG] Sprite problem

    Continued from last post...

    To give the sprite fluent animation you would do this:

    Animation first half
    vb.net Code:
    1. Option Explicit On
    2. Option Strict On
    3.  
    4. Imports Microsoft.DirectX
    5. Imports Microsoft.DirectX.Direct3D
    6.  
    7. Public Class frmMain
    8.  
    9.     Private Structure RECT
    10.  
    11.         Dim Left As Single
    12.         Dim Top As Single
    13.         Dim Right As Single
    14.         Dim Bottom As Single
    15.  
    16.     End Structure
    17.  
    18.     Private Structure Animation_Type
    19.  
    20.         Dim Frame_Size() As RECT
    21.         Dim Number_Of_Frames As Integer
    22.         Dim Number_Of_Textures As Integer
    23.         Dim Current_Frame As Single
    24.         Dim Frame_Counter As Integer
    25.         Dim Speed As Single
    26.         Dim Initial_Frame As Integer
    27.         Dim Mode As Integer 'Single Shot, Loop, etc.
    28.         Dim Offset() As Vector2
    29.         Dim Texture_Number() As Integer
    30.  
    31.     End Structure
    32.  
    33.     Private Structure Sprite_Type
    34.  
    35.         Dim Position As Vector2
    36.         Dim Animation_State As Animation_Type
    37.         <VBFixedString(256)> Dim Texture_Path() As String
    38.         Dim Texture_List() As Texture
    39.         Dim Total_Number_Of_Textures As Integer
    40.         Dim Vertex_List As CustomVertex.TransformedColoredTextured()
    41.         Dim Scale_Factor As Single
    42.  
    43.     End Structure
    44.  
    45.     Private Const COLOR_DEPTH_16_BIT As Format = Format.R5G6B5
    46.     Private Const COLOR_DEPTH_24_BIT As Format = Format.A8R8G8B8
    47.     Private Const COLOR_DEPTH_32_BIT As Format = Format.X8R8G8B8
    48.  
    49.     Private Const ANIMATION_MODE_SINGLE_SHOT As Integer = 0
    50.     Private Const ANIMATION_MODE_LOOP As Integer = 1
    51.  
    52.     Private Device As Device
    53.     Private Display_Mode As DisplayMode
    54.     Private Screen As PresentParameters = New PresentParameters
    55.  
    56.     Private Fullscreen_Enabled As Boolean
    57.     Private Fullscreen_Width As Integer
    58.     Private Fullscreen_Height As Integer
    59.     Private Window_Width As Integer
    60.     Private Window_Height As Integer
    61.     Private Running As Boolean = True
    62.  
    63.     Private Scalar As Vector2
    64.     Private Sprite As Sprite_Type
    65.  
    66.     Private Function Create_Custom_Vertex(ByVal X As Single, ByVal Y As Single, ByVal Z As Single, ByVal Color As Integer, ByVal TU As Integer, ByVal TV As Integer) As CustomVertex.TransformedColoredTextured
    67.  
    68.         Create_Custom_Vertex.Position = New Vector4(X, Y, Z, 1)
    69.         Create_Custom_Vertex.Color = Color
    70.         Create_Custom_Vertex.Tu = TU
    71.         Create_Custom_Vertex.Tv = TV
    72.  
    73.     End Function
    74.  
    75.     Public Function Load_Texture(ByVal File_Path As String, ByVal Transparency_Color As Integer) As Texture
    76.  
    77.         Load_Texture = TextureLoader.FromFile(Device, File_Path, 512, 512, 1, Usage.None, Format.A8B8G8R8, Pool.Managed, Filter.Point, Filter.Point, Transparency_Color)
    78.  
    79.     End Function
    80.  
    81.     Private Sub Setup_Sprite()
    82.  
    83.         If Fullscreen_Enabled = True Then
    84.             Scalar.X = 1
    85.             Scalar.Y = 1
    86.         ElseIf Fullscreen_Enabled = False Then
    87.             Scalar.X = Convert.ToSingle(Window_Width / Fullscreen_Width)
    88.             Scalar.Y = Convert.ToSingle(Window_Height / Fullscreen_Height)
    89.         End If
    90.  
    91.         With Sprite
    92.             .Position.X = 200
    93.             .Position.Y = 400
    94.             .Scale_Factor = 2
    95.             .Vertex_List = New CustomVertex.TransformedColoredTextured(0 To 3) {}
    96.             With .Animation_State
    97.                 .Number_Of_Frames = 6
    98.                 .Number_Of_Textures = 4
    99.                 .Speed = 0.2
    100.                 .Initial_Frame = 0
    101.                 .Mode = ANIMATION_MODE_LOOP
    102.                 ReDim .Frame_Size(.Number_Of_Frames)
    103.                 ReDim .Offset(.Number_Of_Frames)
    104.                 ReDim .Texture_Number(.Number_Of_Frames)
    105.                 .Frame_Size(0).Left = -61 : .Frame_Size(0).Top = -92 : .Frame_Size(0).Right = 61 : .Frame_Size(0).Bottom = 92
    106.                 .Frame_Size(1).Left = -62 : .Frame_Size(1).Top = -91 : .Frame_Size(1).Right = 62 : .Frame_Size(1).Bottom = 91
    107.                 .Frame_Size(2).Left = -61 : .Frame_Size(2).Top = -92 : .Frame_Size(2).Right = 61 : .Frame_Size(2).Bottom = 92
    108.                 .Frame_Size(3).Left = -60 : .Frame_Size(3).Top = -94 : .Frame_Size(3).Right = 60 : .Frame_Size(3).Bottom = 94
    109.                 .Frame_Size(4).Left = -57 : .Frame_Size(4).Top = -95 : .Frame_Size(4).Right = 57 : .Frame_Size(4).Bottom = 95
    110.                 .Frame_Size(5).Left = -60 : .Frame_Size(5).Top = -94 : .Frame_Size(5).Right = 60 : .Frame_Size(5).Bottom = 94
    111.                 Dim I As Integer
    112.                 'Were gonna use the center of the sprite for Position X and Y as well as make the sprite bigger using a scale factor
    113.                 For I = 0 To UBound(.Frame_Size)
    114.                     With .Frame_Size(I)
    115.                         .Left = (.Left / 2) * Sprite.Scale_Factor
    116.                         .Top = (.Top / 2) * Sprite.Scale_Factor
    117.                         .Right = (.Right / 2) * Sprite.Scale_Factor
    118.                         .Bottom = (.Bottom / 2) * Sprite.Scale_Factor
    119.                     End With
    120.                 Next I
    121.                 .Offset(0).X = 0 : .Offset(0).Y = 3
    122.                 .Offset(1).X = -1 : .Offset(1).Y = 4
    123.                 .Offset(2).X = 0 : .Offset(2).Y = 3
    124.                 .Offset(3).X = 0 : .Offset(3).Y = 0
    125.                 .Offset(4).X = -1 : .Offset(4).Y = 0
    126.                 .Offset(5).X = 0 : .Offset(5).Y = 0
    127.                 .Texture_Number(0) = 0
    128.                 .Texture_Number(1) = 1
    129.                 .Texture_Number(2) = 0
    130.                 .Texture_Number(3) = 2
    131.                 .Texture_Number(4) = 3
    132.                 .Texture_Number(5) = 2
    133.  
    134.             End With
    135.  
    136.         End With
    137.  
    138.     End Sub
    139.  
    140.     Public Sub Load_Sprite_Textures()
    141.  
    142.         Dim Current_Texture As Integer
    143.  
    144.         With Sprite
    145.             .Total_Number_Of_Textures = 4
    146.  
    147.             ReDim .Texture_List(.Total_Number_Of_Textures)
    148.             ReDim .Texture_Path(.Total_Number_Of_Textures)
    149.  
    150.             .Texture_Path(0) = Application.StartupPath & "\Ken - Fighting Stance1.png"
    151.             .Texture_Path(1) = Application.StartupPath & "\Ken - Fighting Stance2.png"
    152.             .Texture_Path(2) = Application.StartupPath & "\Ken - Fighting Stance3.png"
    153.             .Texture_Path(3) = Application.StartupPath & "\Ken - Fighting Stance4.png"
    154.  
    155.             For Current_Texture = 0 To .Total_Number_Of_Textures - 1
    156.                 .Texture_List(Current_Texture) = Load_Texture(.Texture_Path(Current_Texture), System.Drawing.Color.FromArgb(255, 255, 0, 255).ToArgb)
    157.             Next Current_Texture
    158.         End With
    159.  
    160.     End Sub
    161.  
    162.     Private Sub Create_Polygon()
    163.  
    164.         Sprite.Vertex_List(0) = Create_Custom_Vertex(0, 0, 0, System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb, 0, 0)
    165.         Sprite.Vertex_List(1) = Create_Custom_Vertex(100, 0, 0, System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb, 1, 0)
    166.         Sprite.Vertex_List(2) = Create_Custom_Vertex(0, 100, 0, System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb, 0, 1)
    167.         Sprite.Vertex_List(3) = Create_Custom_Vertex(100, 100, 0, System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb, 1, 1)
    168.  
    169.     End Sub
    170.  
    171.     Private Sub Animate_Sprite()
    172.  
    173.         Dim Frame As RECT
    174.  
    175.         Device.VertexFormat = CustomVertex.TransformedColoredTextured.Format
    176.  
    177.         With Sprite
    178.             With .Animation_State
    179.                 If .Number_Of_Frames <> 0 Then
    180.                     If .Current_Frame <= 0 Then .Current_Frame = 0
    181.                     Select Case .Mode
    182.                         Case ANIMATION_MODE_SINGLE_SHOT
    183.                             If .Number_Of_Frames = 1 Then
    184.                                 .Current_Frame = 0
    185.                             ElseIf .Number_Of_Frames > 1 Then
    186.                                 If .Current_Frame >= (.Number_Of_Frames - 1) Then
    187.                                     .Current_Frame = (.Number_Of_Frames - 1)
    188.                                 End If
    189.                             End If
    190.                         Case ANIMATION_MODE_LOOP
    191.                             If .Current_Frame > (.Number_Of_Frames - 1) Then
    192.                                 .Current_Frame = 0
    193.                             End If
    194.                     End Select
    195.                 End If
    196.  
    197.                 Frame.Left = (Sprite.Position.X + .Frame_Size(CInt(.Current_Frame)).Left + (.Offset(CInt(.Current_Frame)).X)) * Scalar.X
    198.                 Frame.Top = (Sprite.Position.Y + .Frame_Size(CInt(.Current_Frame)).Top + .Offset(CInt(.Current_Frame)).Y) * Scalar.Y
    199.                 Frame.Right = (Sprite.Position.X + .Frame_Size(CInt(.Current_Frame)).Right + (.Offset(CInt(.Current_Frame)).X)) * Scalar.X
    200.                 Frame.Bottom = (Sprite.Position.Y + .Frame_Size(CInt(.Current_Frame)).Bottom + .Offset(CInt(.Current_Frame)).Y) * Scalar.Y
    201.  
    202.                 With Frame
    203.                     Sprite.Vertex_List(0) = Create_Custom_Vertex(.Left, .Top, 0, System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb, 0, 0)
    204.                     Sprite.Vertex_List(1) = Create_Custom_Vertex(.Right, .Top, 0, System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb, 1, 0)
    205.                     Sprite.Vertex_List(2) = Create_Custom_Vertex(.Left, .Bottom, 0, System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb, 0, 1)
    206.                     Sprite.Vertex_List(3) = Create_Custom_Vertex(.Right, .Bottom, 0, System.Drawing.Color.FromArgb(255, 255, 255, 255).ToArgb, 1, 1)
    207.                 End With
    208.  
    209.                 Device.SetTexture(0, Sprite.Texture_List(Sprite.Animation_State.Texture_Number(CInt(.Current_Frame))))
    210.                 If Running = True Then .Current_Frame += .Speed
    211.             End With
    212.             Device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, .Vertex_List)
    213.         End With
    214.  
    215.     End Sub
    216.  
    217.     Private Sub Set_Renderstates()
    218.  
    219.         'Right here will alphablend the polygon
    220.         Device.SetRenderState(RenderStates.AlphaBlendEnable, True)
    221.  
    222.         'Needed for alphablending
    223.         '----------------------------------------------------------------------------------------------------
    224.         Device.SetTextureStageState(0, TextureStageStates.ColorOperation, TextureOperation.Modulate)
    225.         Device.SetTextureStageState(0, TextureStageStates.ColorArgument1, TextureArgument.TextureColor)
    226.         Device.SetTextureStageState(0, TextureStageStates.ColorArgument2, TextureArgument.Diffuse)
    227.  
    228.         Device.SetTextureStageState(0, TextureStageStates.AlphaOperation, TextureOperation.Modulate)
    229.         Device.SetTextureStageState(0, TextureStageStates.AlphaArgument1, TextureArgument.TextureColor)
    230.         Device.SetTextureStageState(0, TextureStageStates.AlphaArgument2, TextureArgument.Diffuse)
    231.  
    232.         Device.SetRenderState(RenderStates.SourceBlend, Blend.SourceAlpha)
    233.         Device.SetRenderState(RenderStates.DestinationBlend, Blend.InvSourceAlpha)
    234.         Device.SetRenderState(RenderStates.BlendOperation, TextureOperation.Add)
    235.         '----------------------------------------------------------------------------------------------------
    236.  
    237.         'These lines are not needed, but it's nice to be able to filter the
    238.         'textures to make them look nicer.
    239.  
    240.         Device.SetSamplerState(0, SamplerStageStates.MinFilter, TextureFilter.Point)
    241.         Device.SetSamplerState(0, SamplerStageStates.MagFilter, TextureFilter.Point)
    242.  
    243.     End Sub
    244.  
    245.     Private Sub DirectX9_Initialize()
    246.  
    247.         If Fullscreen_Enabled = True Then
    248.             Display_Mode.Width = 800
    249.             Display_Mode.Height = 600
    250.             Display_Mode.Format = COLOR_DEPTH_16_BIT
    251.             'Check to see if fullscreen mode is supported before you use it.
    252.             If Manager.CheckDeviceType(0, DeviceType.Hardware, Display_Mode.Format, Display_Mode.Format, False) Then
    253.                 ' Perfect, this is valid
    254.                 Screen.Windowed = False
    255.                 Screen.BackBufferCount = 1
    256.                 Screen.BackBufferWidth = Display_Mode.Width
    257.                 Screen.BackBufferHeight = Display_Mode.Height
    258.             Else
    259.                 MessageBox.Show("Your video card doesn't support this screen resolution.", "", MessageBoxButtons.OK, MessageBoxIcon.Error)
    260.             End If
    261.         Else
    262.             Screen.Windowed = True
    263.         End If
    264.  
    265.         Screen.SwapEffect = SwapEffect.Copy
    266.         Screen.BackBufferFormat = Display_Mode.Format
    267.  
    268.         'Create our device
    269.         Device = New Device(0, DeviceType.Hardware, Me.Handle, CreateFlags.SoftwareVertexProcessing, Screen)
    270.  
    271.         Set_Renderstates()
    272.  
    273.     End Sub
    274.  
    275.     Private Sub Render()
    276.  
    277.         Device.Clear(ClearFlags.Target, Color.FromArgb(255, 0, 0, 0).ToArgb, 1.0, 0)
    278.         Device.BeginScene()
    279.         Create_Polygon()
    280.         Animate_Sprite()
    281.         Device.EndScene()
    282.         Device.Present()
    283.         Application.DoEvents()
    284.  
    285.     End Sub
    286.  
    287.     Private Sub Game_Loop()
    288.  
    289.         Do While Running = True
    290.             Render()
    291.         Loop
    292.  
    293.     End Sub
    294.  
    295.     Private Sub Main()
    296.  
    297.         If MessageBox.Show("Click Yes to go to full screen (Recommended)", "", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = DialogResult.Yes Then
    298.             Fullscreen_Enabled = True
    299.         End If
    300.  
    301.         Fullscreen_Width = 800
    302.         Fullscreen_Height = 600
    303.         Window_Width = 640
    304.         Window_Height = 480
    305.  
    306.         With Me
    307.             .Show()
    308.             .SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.Opaque, True) 'Do not draw forms background
    309.             .Text = "DirectX Tutorial"
    310.             .Width = Window_Width
    311.             .Height = Window_Height
    312.             If Fullscreen_Enabled = True Then .FormBorderStyle = Windows.Forms.FormBorderStyle.None
    313.         End With
    314.  
    315.         DirectX9_Initialize()
    316.         Load_Sprite_Textures()
    317.         Setup_Sprite()
    318.         Running = True
    319.  
    320.     End Sub

    Continued next post...

  6. #6
    Computer Science BS Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,339

    Re: XNA to DirectX [RPG] Sprite problem

    Continued from last post....

    Animation second half

    vb.net Code:
    1. Private Sub Shutdown()
    2.  
    3.         Dim Current_Texture As Integer
    4.  
    5.         Running = False
    6.         For Current_Texture = 0 To Sprite.Total_Number_Of_Textures - 1
    7.             Sprite.Texture_List(Current_Texture).Dispose() : Sprite.Texture_List(Current_Texture) = Nothing
    8.         Next Current_Texture
    9.         Device = Nothing
    10.         Application.Exit()
    11.  
    12.     End Sub
    13.  
    14.     Private Sub frmMain_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    15.  
    16.         If e.KeyCode = Keys.Escape Then Shutdown()
    17.  
    18.     End Sub
    19.  
    20.     Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    21.  
    22.         Main()
    23.  
    24.     End Sub
    25.  
    26.     Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    27.  
    28.         Shutdown()
    29.  
    30.     End Sub
    31.  
    32.     Private Sub frmMain_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    33.  
    34.         Game_Loop()
    35.  
    36.     End Sub
    37.  
    38.     Private Sub frmMain_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
    39.  
    40.         If Fullscreen_Enabled = False Then
    41.             Running = False 'Stop the loop
    42.             Device.Reset(Screen) 'Reset the device. To not allow stretching, prior to this line, have Screen.Backbufferwidth & heights = 0.
    43.             Set_Renderstates()
    44.             Render() 'So we can see it stretch. As we stretch, especially when stretching larger, we get a black artifact. To avoid this we stop the animation and draw the current frame we have.
    45.             Application.DoEvents() 'Must have to prevent the mouse event from locking up
    46.             Running = True 'Reenable the loop
    47.         End If
    48.  
    49.     End Sub
    50. End Class

    Hopefully you got something out of that little mini tutorial but that should lead you in the right direction in the world of DirectX

    And your sprite class and textures should be coded a bit differently. You could have it to where you have a sub routine that loads all the textures to a sprite texture list, and you can work out the ID numbers to each of the animation states (like in my animation tutorial I showed you.)

    And I can stress it enough, lay off the multithreading...and timers. I explained it all in the last thread, and so did dday afterwards

    If you need help getting a tile engine going let me know.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width