Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Strict On
- Option Explicit On
- Imports System.IO
- Imports Microsoft.Xna.Framework
- Imports Microsoft.Xna.Framework.Graphics
- Public Class XNALoad
- Public Shared grafix As Graphics.GraphicsDevice = Nothing
- Public Shared s_Batch As SpriteBatch
- Public Shared Map As Texture2D
- Public Shared Character As Texture2D
- Public Shared Charac2ter As RenderTarget2D
- Public Shared Function initialize(ByRef surface As PictureBox) As Boolean
- Try
- Dim pparam As New PresentationParameters
- pparam.DeviceWindowHandle = surface.Handle
- pparam.IsFullScreen = False
- Dim grafixAdapt As GraphicsAdapter = GraphicsAdapter.DefaultAdapter
- grafix = New GraphicsDevice(grafixAdapt, GraphicsProfile.HiDef, pparam)
- initialize = True
- Catch ex As Exception
- initialize = False
- End Try
- End Function
- Public Shared Function BitmapToTexture2D(GraphicsDevice As GraphicsDevice, image As System.Drawing.Bitmap) As Texture2D
- Dim bufferSize As Integer = image.Height * image.Width * 4
- ' Create new memory stream and save image to stream so
- ' we don't have to save and read file
- Dim memoryStream As New System.IO.MemoryStream(bufferSize)
- image.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png)
- ' Creates a texture from IO.Stream - our memory stream
- memoryStream.Seek(0, SeekOrigin.Begin)
- Dim texture As Texture2D = Texture2D.FromStream(GraphicsDevice, memoryStream, image.Width, image.Height, False)
- memoryStream.Close()
- Return texture
- End Function
- Public Shared Sub Load_Content()
- If IsNothing(grafix) = False Then
- s_Batch = New SpriteBatch(grafix)
- Map = BitmapToTexture2D(grafix, clsGame.map.P_Canvas)
- Character = BitmapToTexture2D(grafix, clsSprite.FindCharacterSpriteDirection(clsSprite.Direction, clsSprite.iCurrentFrame))
- Else
- Throw New ArgumentNullException("Grafix")
- Exit Sub
- End If
- End Sub
- Public Shared Sub Load_Character()
- If IsNothing(grafix) = False Then
- Character = BitmapToTexture2D(grafix, clsSprite.FindCharacterSpriteDirection(clsSprite.Direction, clsSprite.iCurrentFrame))
- Else
- Throw New ArgumentNullException("Grafix")
- Exit Sub
- End If
- End Sub
- Public Shared Sub DoWorkDraw()
- Do While clsGame.bQuit = False
- grafix.Clear(Color.Black)
- If (clsSprite.inMotion = True) Then
- Load_Character()
- End If
- With s_Batch
- .Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend)
- 'Actually draws map
- 'We add + 30 for the 0 (tile)
- .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)
- 'Yup draws NPC's on map
- 'We add + 30 for the 0 (tile)
- For cNPC As Integer = 0 To clsNPC.NPClist.Count - 1 ' Adds -1 cus 0 is also an id in arraylist clsnpc.npclist
- Dim NPCPOSX As Integer = clsNPC.NPClistCoordsDraw(cNPC).X - 1
- Dim NPCPOSY As Integer = clsNPC.NPClistCoordsDraw(cNPC).Y - 1
- Dim NPCSPRITEID As Integer = clsNPC.NPClistSprite(cNPC)
- Dim NPCFACEID As String = clsNPC.NPClistFace(cNPC)
- Dim NPCFRAMEID As Integer = clsNPC.NPCListFrame(cNPC)
- .Draw(clsNPC.FindNPCSprite(NPCSPRITEID, NPCFACEID, NPCFRAMEID), New Rectangle(CInt(NPCPOSX - clsSprite.Position.X + 30), CInt(NPCPOSY - clsSprite.Position.Y + 30), 32, 32), Color.White)
- Next cNPC
- 'This draws the character
- .Draw(Character, New Rectangle(330, 240, clsSprite.FindCharacterSpriteDirection(clsSprite.Direction, clsSprite.iCurrentFrame).Width, clsSprite.FindCharacterSpriteDirection(clsSprite.Direction, clsSprite.iCurrentFrame).Height), Color.White)
- .End()
- End With
- grafix.Present()
- Loop
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment