Results 1 to 6 of 6

Thread: text fade in

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2000
    Location
    Philadelphia
    Posts
    47

    Question

    I was wondering if anyone knows how to read in a text file into a form... when the next letter is read it, it fades in, not just appears on the screen.. I know it is done in Unreal Tournament if anyone knows what i am talking about...
    U S A
    Visual Studio .NET
    Windows XP

  2. #2
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    sorry I don't have time to explain getting the text...but here is for placing it in a label
    Code:
    dim NewText as string
    lblNewText.backstyle = 0
    lblNewText.caption = NewText
    lblNewText.backcolor = form1.backcolor
    dim r as integer 
    dim g as integer
    dim b as integer
    dim i as integer
    for i = 1 to 255
       r = i
       g = i
       b = i
       lblNewText.forecolor = rgb(r,g,b 
    next i

  3. #3
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    In a module:
    Code:
    Option Explicit
    
    Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
    Private Declare Function GetTextColor Lib "gdi32" (ByVal hdc As Long) As Long
    Private Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
    
    
    Public Sub FadeTextIn(ByVal pHDC As Long, ByVal pStartColor As Long, ByVal pEndColor As Long, ByVal pX As Integer, ByVal pY As Integer, ByVal pStr As String, ByVal pLoopCt As Long)
     Dim iSR As Integer, iSG As Integer, iSB As Integer
     Dim iER As Integer, iEG As Integer, iEB As Integer
     Dim iRChg As Single, iGChg As Single, iBChg As Single
     Dim lOrigTextColor As Long
     Dim iCt As Integer
     Dim lRet As Long
     
     ' Retrieve the original color the Device is using to print text so
     ' it can be restored after we are done
     lOrigTextColor = GetTextColor(pHDC)
     
     ' Retrieve the individual red, green, and blue values for the start color
     iSR = RedAmt(pStartColor)
     iSG = GreenAmt(pStartColor)
     iSB = BlueAmt(pStartColor)
     
     ' Retrieve the individual red, green, and blue values for the start color
     iER = RedAmt(pEndColor)
     iEG = GreenAmt(pEndColor)
     iEB = BlueAmt(pEndColor)
     
     ' Get the amount to change the colors during the loop
     iRChg = (iER - iSR) / pLoopCt
     iGChg = (iEG - iSG) / pLoopCt
     iBChg = (iEB - iSB) / pLoopCt
     
     For iCt = 1 To pLoopCt
     
        'change the color of the Device to the current color
        SetTextColor pHDC, RGB(iSR + iRChg * iCt, iSG + iGChg * iCt, iSB + iBChg * iCt)
        
        ' show the text
        lRet = TextOut(pHDC, pX, pY, pStr, Len(pStr))
        
        ' allow other processes to run
        DoEvents
        
    Next iCt
    
    ' restore the text color to the device
    SetTextColor pHDC, lOrigTextColor
    
    End Sub
    
    Private Function RedAmt(lColor As Long) As Integer
    
        RedAmt = lColor Mod 256
    
    End Function
    
    Private Function GreenAmt(lColor As Long) As Integer
    
        GreenAmt = (lColor / 256) Mod 256
        
    End Function
    
    Private Function BlueAmt(lColor As Long) As Integer
    
        BlueAmt = lColor / &H10000
        
    End Function
    In your form:

    Code:
    Private Sub Command1_Click()
    
        ' fade text from blue to red
        FadeTextIn Me.hdc, RGB(0, 0, 255), RGB(255, 0, 0), 25, 25, "FADE ME IN PLEASE!!!", 10000
        
    End Sub
    Enjoy!
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  4. #4
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Thumbs up

    YoungBuck, your code juz change the color of the text but not fade. Whereas, SteveCRM's code juz too fast. not effect can be saw.

  5. #5
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    I just reread Emerican's original request and thought I would update some code. Use the same code in the module but replace the code in the form with something similar to the following...

    Code:
    Private Sub Form_Load()
        
        Me.BackColor = vbRed
        
    End Sub
    
    Private Sub Command1_Click()
     Dim sText As String
     Dim sChar As String * 1
     Dim ict As Integer
     Dim ix As Integer, iy As Integer
     
     sText = "My Text!!!"
     ix = 50: iy = 50
     
     For ict = 1 To Len(sText)
        
        sChar = Mid(sText, ict, 1)
        
        If Not sChar = " " Then
        
            FadeTextIn Me.hdc, vbRed, vbBlue, ix, iy, sChar, 4000
        
        End If
        
        ix = ix + 8
        
    Next ict
        
    End Sub
    This will fade the characters in one at a time.
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  6. #6
    Fanatic Member MoMad's Avatar
    Join Date
    Oct 2000
    Location
    Seattle, WA
    Posts
    625

    Talking Chuka-Laka!!

    Thas cool.

    but there is a little mistake here.

    Code:
    Dim NewText As String
    lblNewText.BackStyle = 0
    lblNewText.caption = NewText
    lblNewText.backcolor = form1.backcolor
    dim r as integer
    dim g as integer
    dim b as integer
    dim i as integer
    For i = 1 to 255
       r = i
       g = i
       b = i
       lblNewText.forecolor = rgb(r,g,b)
    Next i
    it would be better to change integer to long.
    and instead of having dim r,g,b just have dim i... since you wont be doing any color effects except for dark to light.

    and change the last line:

    lblNewText.forecolor = rgb(r,g,b)
    to

    lblNewText.forecolor = rgb(i,i,i)
    and add another loop that loops a 1000times to slow down animation.

    like this:
    for j = 0 to 1000
    next j

    thas all; its called an empty loop and its used to slow down the program if cpu is too fast!!! ---by the way, u can use time Api to slow down the loop!!!

    :P
    Good luck m8.
    :MoMad:
    Nice Sig!

    http://go.to/momad/ Status: Not Ready

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width