×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Wont Display My Sprite!
2

Wont Display My Sprite!

Wont Display My Sprite!

(OP)
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

RE: Wont Display My Sprite!

N.B.  Are you using Direct3D Lighting? If not, be sure to turn D3D Lighting OFF.  I'm not sure how this would be done in VB, but in C++ it would involve a call to IDirect3DDevice::SetRenderState(D3DRS_LIGHTING, FALSE).

RE: Wont Display My Sprite!

(OP)
Thanks apatterno.

Dont be small.  be BIG

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close