Guest User

Untitled

a guest
Mar 13th, 2014
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. Public Class DXSprite
  2.  
  3. 'The rectangular area of a texture that will be displayed on a sprite object
  4. Private mSourceRectangle As Rectangle
  5. Public ReadOnly Property SourceRectangle() As Rectangle
  6. Get
  7. Return mSourceRectangle
  8. End Get
  9. End Property
  10.  
  11. 'The texture to be applied to a sprite object
  12. Private mTexture As Microsoft.DirectX.Direct3D.Texture
  13. Public ReadOnly Property Texture() As Microsoft.DirectX.Direct3D.Texture
  14. Get
  15. Return mTexture
  16. End Get
  17. End Property
  18.  
  19. 'Description: The class constructor. Store the source rectangle and load an image into a texture.
  20. Public Sub New(ByVal theDevice As Microsoft.DirectX.Direct3D.Device, ByVal isLoadedFromFile As Boolean, ByVal theXpos As Integer, ByVal theYpos As Integer, ByVal theHeight As Integer, ByVal theWidth As Integer, Optional ByVal theTexture As Microsoft.DirectX.Direct3D.Texture = Nothing, Optional ByVal theTextureName As String = "", Optional ByVal LoadTexture As Boolean = False)
  21. 'Store the rectangle for the sprite, this is the size of a rectangle on an image that makes up the
  22. 'texture for the sprite.
  23. mSourceRectangle = New Rectangle(theXpos, theYpos, theWidth, theHeight)
  24.  
  25. 'Load the image, either from a file or from the project in a stream
  26. If isLoadedFromFile = True And LoadTexture = False Then
  27. mTexture = Microsoft.DirectX.Direct3D.TextureLoader.FromFile(theDevice, theTextureName, theWidth, theHeight, 24, 0, Microsoft.DirectX.Direct3D.Format.Unknown, Microsoft.DirectX.Direct3D.Pool.Default, Microsoft.DirectX.Direct3D.Filter.None, Microsoft.DirectX.Direct3D.Filter.None, 0)
  28. ElseIf (LoadTexture = False) Then
  29. mTexture = Microsoft.DirectX.Direct3D.TextureLoader.FromStream(theDevice, Me.GetType().Assembly.GetManifestResourceStream(theTextureName))
  30. End If
  31.  
  32. If (LoadTexture = True) Then
  33. mTexture = theTexture
  34. End If
  35. End Sub
  36.  
  37. 'Description: Class destructor, destroy the objects
  38. Protected Overrides Sub Finalize()
  39. Call Dispose()
  40.  
  41. MyBase.Finalize()
  42. End Sub
  43.  
  44. 'Description: Dispose of the objects created in the class
  45. Private Sub Dispose()
  46. mSourceRectangle = Nothing
  47.  
  48. If Not (mTexture Is Nothing) Then
  49. mTexture.Dispose()
  50. End If
  51. mTexture = Nothing
  52. End Sub
  53.  
  54. End Class
Advertisement
Add Comment
Please, Sign In to add comment