Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class DXSprite
- 'The rectangular area of a texture that will be displayed on a sprite object
- Private mSourceRectangle As Rectangle
- Public ReadOnly Property SourceRectangle() As Rectangle
- Get
- Return mSourceRectangle
- End Get
- End Property
- 'The texture to be applied to a sprite object
- Private mTexture As Microsoft.DirectX.Direct3D.Texture
- Public ReadOnly Property Texture() As Microsoft.DirectX.Direct3D.Texture
- Get
- Return mTexture
- End Get
- End Property
- 'Description: The class constructor. Store the source rectangle and load an image into a texture.
- 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)
- 'Store the rectangle for the sprite, this is the size of a rectangle on an image that makes up the
- 'texture for the sprite.
- mSourceRectangle = New Rectangle(theXpos, theYpos, theWidth, theHeight)
- 'Load the image, either from a file or from the project in a stream
- If isLoadedFromFile = True And LoadTexture = False Then
- 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)
- ElseIf (LoadTexture = False) Then
- mTexture = Microsoft.DirectX.Direct3D.TextureLoader.FromStream(theDevice, Me.GetType().Assembly.GetManifestResourceStream(theTextureName))
- End If
- If (LoadTexture = True) Then
- mTexture = theTexture
- End If
- End Sub
- 'Description: Class destructor, destroy the objects
- Protected Overrides Sub Finalize()
- Call Dispose()
- MyBase.Finalize()
- End Sub
- 'Description: Dispose of the objects created in the class
- Private Sub Dispose()
- mSourceRectangle = Nothing
- If Not (mTexture Is Nothing) Then
- mTexture.Dispose()
- End If
- mTexture = Nothing
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment