Guest User

Untitled

a guest
Mar 13th, 2014
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. Option Strict On
  2. Option Explicit On
  3.  
  4. Imports System.IO
  5. Imports Microsoft.Xna.Framework
  6. Imports Microsoft.Xna.Framework.Graphics
  7.  
  8. Public Class XNALoad
  9.  
  10. Public Shared grafix As Graphics.GraphicsDevice = Nothing
  11. Public Shared s_Batch As SpriteBatch
  12. Public Shared Map As Texture2D
  13. Public Shared Character As Texture2D
  14. Public Shared Charac2ter As RenderTarget2D
  15.  
  16. Public Shared Function initialize(ByRef surface As PictureBox) As Boolean
  17. Try
  18. Dim pparam As New PresentationParameters
  19. pparam.DeviceWindowHandle = surface.Handle
  20. pparam.IsFullScreen = False
  21.  
  22. Dim grafixAdapt As GraphicsAdapter = GraphicsAdapter.DefaultAdapter
  23.  
  24. grafix = New GraphicsDevice(grafixAdapt, GraphicsProfile.HiDef, pparam)
  25.  
  26.  
  27.  
  28. initialize = True
  29. Catch ex As Exception
  30. initialize = False
  31. End Try
  32. End Function
  33.  
  34. Public Shared Function BitmapToTexture2D(GraphicsDevice As GraphicsDevice, image As System.Drawing.Bitmap) As Texture2D
  35. Dim bufferSize As Integer = image.Height * image.Width * 4
  36.  
  37. ' Create new memory stream and save image to stream so
  38. ' we don't have to save and read file
  39. Dim memoryStream As New System.IO.MemoryStream(bufferSize)
  40. image.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png)
  41.  
  42. ' Creates a texture from IO.Stream - our memory stream
  43. memoryStream.Seek(0, SeekOrigin.Begin)
  44. Dim texture As Texture2D = Texture2D.FromStream(GraphicsDevice, memoryStream, image.Width, image.Height, False)
  45.  
  46. memoryStream.Close()
  47. Return texture
  48. End Function
  49.  
  50. Public Shared Sub Load_Content()
  51. If IsNothing(grafix) = False Then
  52. s_Batch = New SpriteBatch(grafix)
  53.  
  54. Map = BitmapToTexture2D(grafix, clsGame.map.P_Canvas)
  55. Character = BitmapToTexture2D(grafix, clsSprite.FindCharacterSpriteDirection(clsSprite.Direction, clsSprite.iCurrentFrame))
  56. Else
  57. Throw New ArgumentNullException("Grafix")
  58. Exit Sub
  59. End If
  60.  
  61. End Sub
  62.  
  63. Public Shared Sub Load_Character()
  64. If IsNothing(grafix) = False Then
  65. Character = BitmapToTexture2D(grafix, clsSprite.FindCharacterSpriteDirection(clsSprite.Direction, clsSprite.iCurrentFrame))
  66. Else
  67. Throw New ArgumentNullException("Grafix")
  68. Exit Sub
  69. End If
  70.  
  71. End Sub
  72.  
  73. Public Shared Sub DoWorkDraw()
  74. Do While clsGame.bQuit = False
  75.  
  76. grafix.Clear(Color.Black)
  77.  
  78. If (clsSprite.inMotion = True) Then
  79. Load_Character()
  80. End If
  81.  
  82. With s_Batch
  83. .Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend)
  84. 'Actually draws map
  85. 'We add + 30 for the 0 (tile)
  86. .Draw(Map, New Rectangle(CInt(-clsSprite.Position.X + 30), CInt(-clsSprite.Position.Y + 30), clsGame.map.P_Canvas.Width, clsGame.map.P_Canvas.Height), Color.White)
  87.  
  88. 'Yup draws NPC's on map
  89. 'We add + 30 for the 0 (tile)
  90.  
  91. For cNPC As Integer = 0 To clsNPC.NPClist.Count - 1 ' Adds -1 cus 0 is also an id in arraylist clsnpc.npclist
  92. Dim NPCPOSX As Integer = clsNPC.NPClistCoordsDraw(cNPC).X - 1
  93. Dim NPCPOSY As Integer = clsNPC.NPClistCoordsDraw(cNPC).Y - 1
  94. Dim NPCSPRITEID As Integer = clsNPC.NPClistSprite(cNPC)
  95. Dim NPCFACEID As String = clsNPC.NPClistFace(cNPC)
  96. Dim NPCFRAMEID As Integer = clsNPC.NPCListFrame(cNPC)
  97.  
  98. .Draw(clsNPC.FindNPCSprite(NPCSPRITEID, NPCFACEID, NPCFRAMEID), New Rectangle(CInt(NPCPOSX - clsSprite.Position.X + 30), CInt(NPCPOSY - clsSprite.Position.Y + 30), 32, 32), Color.White)
  99. Next cNPC
  100.  
  101. 'This draws the character
  102. .Draw(Character, New Rectangle(330, 240, clsSprite.FindCharacterSpriteDirection(clsSprite.Direction, clsSprite.iCurrentFrame).Width, clsSprite.FindCharacterSpriteDirection(clsSprite.Direction, clsSprite.iCurrentFrame).Height), Color.White)
  103. .End()
  104. End With
  105.  
  106. grafix.Present()
  107. Loop
  108. End Sub
  109. End Class
Advertisement
Add Comment
Please, Sign In to add comment