aaahhhrrggghhhh
Programmer
Hello.
I am currently trying some code in VB using DX8.1. I have created a class module "Sprite", and "Sprites" as the container module.
In "Sprites" I have a sub called DrawSprite (see below) which takes the data from the sprite to be displayed and displays it. However, it is not displaying it. There are no error messages (or "On Error..."
, so I can only assume that it is a problem with the code more then the data.
Here is the CUSTOMVERTEX type :
'This structure describes a custom vertex.
'its declaration is in a global module
Public Type CUSTOMVERTEX
x As Single
y As Single
z As Single
rhw As Single
color As Long
specular As Long
tu As Single
tv As Single
End Type
Now here is the code :
Public Sub DrawTheDamnedThing(ByRef SpriteToDraw As Sprite, siElement As Single)
'whew! Now draw it, gulp ...
Dim myTempCUSTOMVERTEX(3) As CUSTOMVERTEX
'SpriteToDraw is the sprite to draw, siElement is the actual frame number
DoEvents
'set the billboard
With myTempCUSTOMVERTEX(0)
' .x = 0: .y = SpriteHeight
.x = SpriteToDraw.SpritePos.x: .y = SpriteToDraw.SpritePos.y + SpriteToDraw.SpriteDimensionsHeight
.tu = 0: .tv = 1
.rhw = 0
.color = SpriteToDraw.SpriteTransparencyColor
End With
With myTempCUSTOMVERTEX(1)
.x = SpriteToDraw.SpritePos.x: .y = SpriteToDraw.SpritePos.y
.tu = 0: .tv = 0
.rhw = 0
.color = SpriteToDraw.SpriteTransparencyColor
End With
With myTempCUSTOMVERTEX(2)
' .x = SpriteWidth: .y = SpriteHeight
.x = SpriteToDraw.SpritePos.x + SpriteToDraw.SpriteDimensionsWidth: .y = SpriteToDraw.SpritePos.y + SpriteToDraw.SpriteDimensionsHeight
.tu = 1: .tv = 1
.rhw = 0
.color = SpriteToDraw.SpriteTransparencyColor
End With
With myTempCUSTOMVERTEX(3)
' .x = SpriteWidth: .y = 0
.x = SpriteToDraw.SpritePos.x + SpriteToDraw.SpriteDimensionsWidth: .y = SpriteToDraw.SpritePos.y
.tu = 1: .tv = 0
.rhw = 0
.color = SpriteToDraw.SpriteTransparencyColor
End With
'so turn alpha blending on
Call oD3DDevice.SetRenderState(D3DRS_ALPHABLENDENABLE, 1)
Set mvarCurrentTexture = oD3DX.CreateTextureFromFileEx( _
oD3DDevice, _
SpriteToDraw.TextureFilename, _
SpriteToDraw.TextureSizeWidth, _
SpriteToDraw.TextureSizeHeight, _
D3DX_DEFAULT, _
0, _
D3DFMT_UNKNOWN, _
D3DPOOL_MANAGED, _
D3DX_FILTER_POINT, _
D3DX_FILTER_POINT, _
SpriteToDraw.SpriteTransparencyColor, _
ByVal 0, _
ByVal 0)
Call oD3DDevice.SetTexture(0, mvarCurrentTexture)
Call oD3DDevice.DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, myTempCUSTOMVERTEX(0), Len(myTempCUSTOMVERTEX(3)))
DoEvents
If displayxyz = False Then GoTo skipoutpvertexinfo
Debug.Print "--VERTEX INFO--------------------"
Debug.Print "Time:" & Format(Now, "dd mmm yyyy hh:nn:ss"
For i = 0 To 3
With myTempCUSTOMVERTEX(i)
Debug.Print "myTempCUSTOMVERTEX(" & i & "
:"
Debug.Print " x = " & .x & " y = " & .y & " z = " & .z & " tu = " & .tu & " tv = " & .tv & " color = " & .color & " .rhw = " & .rhw & " specular = " & .specular
End With
Next i
Call DisplaySpriteInfo(SpriteToDraw)
displayxyz = False
skipoutpvertexinfo:
Call oD3DDevice.SetRenderState(D3DRS_ALPHABLENDENABLE, 0)
End Sub
Private Sub DisplaySpriteInfo(spSprite As Sprite)
Debug.Print "--SPRITE INFO------------------------------"
Debug.Print "Time:" & Format(Now, "dd mmm yyyy hh:nn:ss"
Debug.Print "Sprite Name : " & spSprite.SpriteName
Debug.Print "Sprite Sub Name : " & spSprite.SpriteSubName
Debug.Print "Texture Filename : " & spSprite.TextureFilename
Debug.Print "Texture Size (Height) : " & spSprite.TextureSizeHeight
Debug.Print "Texture Size (Width) : " & spSprite.TextureSizeWidth
Debug.Print "Sprite Size (Height) : " & spSprite.SpriteDimensionsHeight
Debug.Print "Sprite Size (Width) : " & spSprite.SpriteDimensionsWidth
Debug.Print "Number Of Frames Accross : " & spSprite.NoFramesAccross
Debug.Print "Number Of Frames Down : " & spSprite.NoFramesDown
Debug.Print "Total Frame Count : " & spSprite.FrameCount
Debug.Print "Current Frame Displayed : " & spSprite.CurrentFrameDisplayed
Debug.Print "Direction To Go : " & spSprite.DirectionToGo
Debug.Print "Sprite Position (x,y) : (" & spSprite.SpritePos.x & "," & spSprite.SpritePos.y & "
"
Debug.Print "Sprite Transparency color : " & CStr(Hex(spSprite.SpriteTransparencyColor))
End Sub
'----------------------------
OK, so when I run the code, the output in imm. window is :
--VERTEX INFO--------------------
Time:13 Dec 2002 11:54:22
myTempCUSTOMVERTEX(0) :
x = 0 y = 82 z = 0 tu = 0 tv = 1 color = -65536 .rhw = 0 specular = 0
myTempCUSTOMVERTEX(1) :
x = 0 y = 0 z = 0 tu = 0 tv = 0 color = -65536 .rhw = 0 specular = 0
myTempCUSTOMVERTEX(2) :
x = 74 y = 82 z = 0 tu = 1 tv = 1 color = -65536 .rhw = 0 specular = 0
myTempCUSTOMVERTEX(3) :
x = 74 y = 0 z = 0 tu = 1 tv = 0 color = -65536 .rhw = 0 specular = 0
--SPRITE INFO------------------------------
Time:13 Dec 2002 11:54:22
Sprite Name : Sheila
Sprite Sub Name : WalkLeft
Texture Filename : C:\My Download Files\GamesAttempts\mycode\sheila2-3.bmp
Texture Size (Height) : 82
Texture Size (Width) : 148
Sprite Size (Height) : 82
Sprite Size (Width) : 74
Number Of Frames Accross : 2
Number Of Frames Down : 1
Total Frame Count : 2
Current Frame Displayed : 0
Direction To Go : 5
Sprite Position (x,y) : (0,0)
Sprite Transparency color : FFFF0000
So this proves that the data that I want is being passed to the sub, and also proves that the sub itself is being processed, but the sprite is not appearing.
Is it possible, therefore, for somebody to take a quick look and give me some feedback?
Cheers Dont be small. be BIG
I am currently trying some code in VB using DX8.1. I have created a class module "Sprite", and "Sprites" as the container module.
In "Sprites" I have a sub called DrawSprite (see below) which takes the data from the sprite to be displayed and displays it. However, it is not displaying it. There are no error messages (or "On Error..."
Here is the CUSTOMVERTEX type :
'This structure describes a custom vertex.
'its declaration is in a global module
Public Type CUSTOMVERTEX
x As Single
y As Single
z As Single
rhw As Single
color As Long
specular As Long
tu As Single
tv As Single
End Type
Now here is the code :
Public Sub DrawTheDamnedThing(ByRef SpriteToDraw As Sprite, siElement As Single)
'whew! Now draw it, gulp ...
Dim myTempCUSTOMVERTEX(3) As CUSTOMVERTEX
'SpriteToDraw is the sprite to draw, siElement is the actual frame number
DoEvents
'set the billboard
With myTempCUSTOMVERTEX(0)
' .x = 0: .y = SpriteHeight
.x = SpriteToDraw.SpritePos.x: .y = SpriteToDraw.SpritePos.y + SpriteToDraw.SpriteDimensionsHeight
.tu = 0: .tv = 1
.rhw = 0
.color = SpriteToDraw.SpriteTransparencyColor
End With
With myTempCUSTOMVERTEX(1)
.x = SpriteToDraw.SpritePos.x: .y = SpriteToDraw.SpritePos.y
.tu = 0: .tv = 0
.rhw = 0
.color = SpriteToDraw.SpriteTransparencyColor
End With
With myTempCUSTOMVERTEX(2)
' .x = SpriteWidth: .y = SpriteHeight
.x = SpriteToDraw.SpritePos.x + SpriteToDraw.SpriteDimensionsWidth: .y = SpriteToDraw.SpritePos.y + SpriteToDraw.SpriteDimensionsHeight
.tu = 1: .tv = 1
.rhw = 0
.color = SpriteToDraw.SpriteTransparencyColor
End With
With myTempCUSTOMVERTEX(3)
' .x = SpriteWidth: .y = 0
.x = SpriteToDraw.SpritePos.x + SpriteToDraw.SpriteDimensionsWidth: .y = SpriteToDraw.SpritePos.y
.tu = 1: .tv = 0
.rhw = 0
.color = SpriteToDraw.SpriteTransparencyColor
End With
'so turn alpha blending on
Call oD3DDevice.SetRenderState(D3DRS_ALPHABLENDENABLE, 1)
Set mvarCurrentTexture = oD3DX.CreateTextureFromFileEx( _
oD3DDevice, _
SpriteToDraw.TextureFilename, _
SpriteToDraw.TextureSizeWidth, _
SpriteToDraw.TextureSizeHeight, _
D3DX_DEFAULT, _
0, _
D3DFMT_UNKNOWN, _
D3DPOOL_MANAGED, _
D3DX_FILTER_POINT, _
D3DX_FILTER_POINT, _
SpriteToDraw.SpriteTransparencyColor, _
ByVal 0, _
ByVal 0)
Call oD3DDevice.SetTexture(0, mvarCurrentTexture)
Call oD3DDevice.DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, myTempCUSTOMVERTEX(0), Len(myTempCUSTOMVERTEX(3)))
DoEvents
If displayxyz = False Then GoTo skipoutpvertexinfo
Debug.Print "--VERTEX INFO--------------------"
Debug.Print "Time:" & Format(Now, "dd mmm yyyy hh:nn:ss"
For i = 0 To 3
With myTempCUSTOMVERTEX(i)
Debug.Print "myTempCUSTOMVERTEX(" & i & "
Debug.Print " x = " & .x & " y = " & .y & " z = " & .z & " tu = " & .tu & " tv = " & .tv & " color = " & .color & " .rhw = " & .rhw & " specular = " & .specular
End With
Next i
Call DisplaySpriteInfo(SpriteToDraw)
displayxyz = False
skipoutpvertexinfo:
Call oD3DDevice.SetRenderState(D3DRS_ALPHABLENDENABLE, 0)
End Sub
Private Sub DisplaySpriteInfo(spSprite As Sprite)
Debug.Print "--SPRITE INFO------------------------------"
Debug.Print "Time:" & Format(Now, "dd mmm yyyy hh:nn:ss"
Debug.Print "Sprite Name : " & spSprite.SpriteName
Debug.Print "Sprite Sub Name : " & spSprite.SpriteSubName
Debug.Print "Texture Filename : " & spSprite.TextureFilename
Debug.Print "Texture Size (Height) : " & spSprite.TextureSizeHeight
Debug.Print "Texture Size (Width) : " & spSprite.TextureSizeWidth
Debug.Print "Sprite Size (Height) : " & spSprite.SpriteDimensionsHeight
Debug.Print "Sprite Size (Width) : " & spSprite.SpriteDimensionsWidth
Debug.Print "Number Of Frames Accross : " & spSprite.NoFramesAccross
Debug.Print "Number Of Frames Down : " & spSprite.NoFramesDown
Debug.Print "Total Frame Count : " & spSprite.FrameCount
Debug.Print "Current Frame Displayed : " & spSprite.CurrentFrameDisplayed
Debug.Print "Direction To Go : " & spSprite.DirectionToGo
Debug.Print "Sprite Position (x,y) : (" & spSprite.SpritePos.x & "," & spSprite.SpritePos.y & "
Debug.Print "Sprite Transparency color : " & CStr(Hex(spSprite.SpriteTransparencyColor))
End Sub
'----------------------------
OK, so when I run the code, the output in imm. window is :
--VERTEX INFO--------------------
Time:13 Dec 2002 11:54:22
myTempCUSTOMVERTEX(0) :
x = 0 y = 82 z = 0 tu = 0 tv = 1 color = -65536 .rhw = 0 specular = 0
myTempCUSTOMVERTEX(1) :
x = 0 y = 0 z = 0 tu = 0 tv = 0 color = -65536 .rhw = 0 specular = 0
myTempCUSTOMVERTEX(2) :
x = 74 y = 82 z = 0 tu = 1 tv = 1 color = -65536 .rhw = 0 specular = 0
myTempCUSTOMVERTEX(3) :
x = 74 y = 0 z = 0 tu = 1 tv = 0 color = -65536 .rhw = 0 specular = 0
--SPRITE INFO------------------------------
Time:13 Dec 2002 11:54:22
Sprite Name : Sheila
Sprite Sub Name : WalkLeft
Texture Filename : C:\My Download Files\GamesAttempts\mycode\sheila2-3.bmp
Texture Size (Height) : 82
Texture Size (Width) : 148
Sprite Size (Height) : 82
Sprite Size (Width) : 74
Number Of Frames Accross : 2
Number Of Frames Down : 1
Total Frame Count : 2
Current Frame Displayed : 0
Direction To Go : 5
Sprite Position (x,y) : (0,0)
Sprite Transparency color : FFFF0000
So this proves that the data that I want is being passed to the sub, and also proves that the sub itself is being processed, but the sprite is not appearing.
Is it possible, therefore, for somebody to take a quick look and give me some feedback?
Cheers Dont be small. be BIG