Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: font animation possible?

  1. #11
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi,

    it is relatively easy, have a look here:
    Function Custom_Cycle_Next( nValue As Number, nMin As Number, nMax As Number, Optional nStep As Number = 1) As Number
      variable = variable + nStep
      If nValue > nMax Then nValue = nMin
      If nValue < nMin Then nValue = nMax 
      
      Function = nValue
    End Function
    
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  2. #12
    my mistake was I tried function with a do/loop and for/next statements. many thanks petr, solution looks so easy, but not for me (!), thought too complicated! bye, largo

  3. #13
    how I can set the color (background) of a FONT transparent? That's possible?

    see simple example with question:

     
       ' Empty GUI script created on 01-15-2013 18:06:16 by  (thinAir)
     
    
     Uses "UI", "console"
        
     ' -- ID numbers of controls
     Begin ControlID
       %myCanvas        
       %refresh, %stops
       %bClose
       %tAnimationTimer
     End ControlID
        
     ' -- Create dialog here
     Function TBMain()
       Local hDlg As Long, mygraf As Long, counts As Long
        
       Dialog New 0, "Moving canvas Box_sphere + Font transparence?_1c",-1,-1, 300, 240,  
                                          %WS_POPUP | %WS_VISIBLE |  
                                          %WS_CLIPCHILDREN | %WS_CAPTION |  
                                          %WS_SYSMENU | %WS_MINIMIZEBOX, 0 To hDlg
            
       Dim cx, cy As Long
       Dialog Pixels hDlg, 300, 300 To Units cx, cy
       Control Add Canvas, hDlg, %myCanvas, "", 5, 5, cx, cy
                                
       Control Add Button, hDlg, %refresh, "refresh", 10+cx, 5, 50, 14, Call refreshProc
       Control Add Button, hDlg, %stops, "stops", 10+cx, 25, 50, 14, Call stopProc
       Control Add Button, hDlg, %bClose, "Close", 20, 220, 50, 14, Call bCloseProc
         
       Canvas_Attach hDlg,%myCanvas                                                
            
       Dialog Show Modal hDlg, Call dlgProc
         Do
           Dialog DoEvents To Counts
         Loop Until Counts = 0
        
     End Function
        
     ' -- Callback for dialog -------------
     CallBack Function dlgProc()
       Static myvalue As Long
        
       Local mousePosition As POINTAPI
       Local locX, locY, colrVal As Long
            
       Select Case CBMSG
              
         Case %WM_INITDIALOG     
           ' -- Put code to be executed after dialog creation here
           Dialog Set Timer CBHNDL, %tAnimationTimer, 10, %NULL      
             
           ' -- Attach canvas for double buffer
           Canvas_Attach(CBHNDL, %myCanvas, %TRUE)       '%FALSE
                        
         Case %WM_TIMER  
           If CBCTL = %tAnimationTimer Then
             DrawGraphics(CBHNDL, %myCanvas)             
           End If     
            
         Case %WM_DESTROY
           Dialog Kill Timer CBHNDL, %tAnimationTimer
               
         Case %WM_CLOSE
        
       End Select
          
     End Function
         
     ' -- Callback for close button
     CallBack Function bCloseProc()
        
       If CBMSG = %WM_COMMAND Then      
         If CBCTLMSG = %BN_CLICKED Then
           ' -- Closes the dialog
           Dialog End CBHNDL
         End If
       End If
        
     End Function
        
     ' -- Refresh button  
     CallBack Function refreshProc()
        
       If CBMSG = %WM_COMMAND Then      
         If CBCTLMSG = %BN_CLICKED Then
           
           Dialog Kill Timer CBHNDL, %tAnimationTimer
           Dialog Set Timer CBHNDL, %tAnimationTimer, 10, %NULL      
              
         End If
       End If
        
     End Function  
       
     ' -- Stop button
     CallBack Function stopProc()
        
       If CBMSG = %WM_COMMAND Then      
         If CBCTLMSG = %BN_CLICKED Then
           
           Dialog Kill Timer CBHNDL, %tAnimationTimer
            
         End If
       End If
        
     End Function
        
     '---------------------------------------------------------->      
     Sub DrawGraphics(ByVal hWnd As Long, ByVal lCanvas As Long)
     '---------------------------------------------------------->
        Local InDrawing As Long   
        Local z, v, r, g, b As Long   
        Local hDlg, mygraf As Long
        Local oldx, oldy As Double
        Local myExit As Long
        Local t As Single
        Dim tx As Double, ty As Double
          
        ' -- STATICS - they remember their value
        Static vx As Double = -1
        Static vy As Double = 20    
        Static yPush As Double
           
        r = 228
        g = 255
        b = 0
        v = Rgb(r, g, b)   
        z = (r + g + b)\3
          
        ' -- More elegant than single line IF                 
        z = IIf(z < 128, 255, 0)                    
             
        z = Rgb(100, 220, 40)
        Canvas_Clear v            
        Canvas_Color z, v
        Canvas_Width 1          
        oldx = vx
        oldy = vy       
          
        ' -- Imitation of FOR cycles by decomposig step by step
        vx = CYCLE_Next(vx, 20, 200, 1.5)    
        'vx = CYCLE_Next(vx, -1, 175, 5.5)
        'vy = CYCLE_Next(vy, 10, 125, 4.5)
               
        'If vx = -1 Then     
           'ypush = CYCLE_Next(ypush, -1, 175, 5.5)         
        'End If                        
            
         Canvas_Box(oldx,oldy, oldx+20,oldy+20,0,%GREEN,%GREEN)
         oldx = vx : oldy = vy               
                
         Canvas_Clear %myCanvas   
         Canvas_Clear(Rgb(100,220,0))
          
         Canvas_Box(vx,vy, vx+20,vy+20,0,%RED,%GREEN)         
         Canvas_Ellipse(vx+50, vy+50, vx+30, vy+30,%GREEN ,%RED, 0 )
         Canvas_Color z,v
          
         '- how to set font background transparent ? -------->
          
         '-- simple font part ------------------------------->   
             Canvas_Font "Comic Sans MS", 18, 0
             'Canvas_SetPos(10+vx/4,80+vy/4)
             Canvas_SetPos(1+vx/4,8+vy/4)
             Canvas_Print "Canvas Font test: "+Str$(vx,vy)
             Canvas_Color(Rgb(255,10,100))
         '-- simple font part ------------------------------->
           
           
         Canvas_Redraw
           
     End Sub
                                                                                      '=1
    


    bye, largo

  4. #14
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi,

    Canvas_Color has two parameters - foreground and background. If you want to print just text without highlight, pass -2 as background parameter.
    It is documented, help file says:
    If the background parameter is -2, the background is not painted, allowing the content behind to become visible

    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  5. #15
    thank you petr for your answer.
    new question: what I can do for the best way to load a picture (image) file and how I can get a control for that picture with an equate (%picCanvas) and features like for example a button control or something like that? next idea was to load several pictures like my "puzzle game" with a lot of buttons.

    my idea:

    ' Empty GUI script created on 01-19-2013 19:14:20 by largo_winch  (thinAir)
    Uses "console", "ui"
    Begin Const
      %PicsCount       = 8
      %NumberofPics    = 12
      %ButtonClose     = 100
      %cCanvas
      %picCanvas       
      %tAnimationTimer   
      %refresh, %stops
    End Const
    Randomize Timer
    '-----------------------------> MAIN APPLICATION ----------------------------->
    Function TBMain() As Long
    Local hDlg,cx,cy As Long
    Local x,y,nWidth, nHeight As Long
    Local sImageSmall As String = APP_SourcePath+"thorLogo.bmp"
      
      Dialog New 0, "Picture_test canvas",-1,-1, cx+%NumberofPics *%PicsCount+160 , cy+140+(%NumberofPics) *%PicsCount, _  
                                       %WS_POPUP         Or _
                                       %WS_VISIBLE       Or _
                                       %WS_CLIPCHILDREN  Or _
                                       %WS_CAPTION       Or _
                                       %WS_SYSMENU       Or _
                                       %WS_MINIMIZEBOX Or %WS_MAXIMIZEBOX,     _
                                       0 To hDlg
      
      Control Add Button, hDlg, %refresh, "refresh", 10+cx, 85, 80, 18, Call refreshProc
      Control Add Button, hDlg, %stops, "stops", 10+cx, 105, 80, 18, Call stopProc
      
      Dialog  Set Color hDlg, -1, Rgb(95, 185, 185)
       
      Dialog Show Modal hDlg Call cbPicDialog
      
    End Function
    
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~> test Callback, not perfect ------> 
    CallBack Function cbPicDialog() As Long
      
      Local sImageSmall As String = APP_SourcePath+"thorLogo.bmp"
      Static TimerValue As Double     
      Static vx, vy As Double
         
      ' -- Test for messages
      Select Case Callback_Message    
        Case %WM_INITDIALOG
    'xx !! -- question if thats possible to make several number of pics here ? ---------------     
    ' CONTROL ADD BITMAP, CBHNDL, %PICCANVAS,"",vx,vy,64,64 ' something like that I am looking for
      For vy = 0 To %NumberofPics -1
        For vx = 0 To %NumberofPics -1               
               Control Add Canvas, CBHNDL, %picCanvas, "", vx, vy, 64,64 'nWidth, nHeight 
               Control Add Canvas, CBHNDL, %picCanvas, "", vx+70, vy, 64,64 'nWidth, nHeight 
               'Control Add Canvas, CBHNDL, %picCanvas, ""+sImageSmall, vx*%PicsCount, vy*%PicsCount, 16+%PicsCount,16+%PicsCount 'nWidth, nHeight 
        Next
      Next                
          Canvas_Attach(CBHNDL, %picCanvas, TRUE)            
          Canvas_Attach(CBHNDL, %picCanvas, TRUE)
          Canvas_BitmapRender(sImageSmall)  
    'xx !! -- question if thats possible to make several numberofpics here ? ---------------     
                  
          'Canvas_Redraw
          ' -- Put code to be executed after dialog creation here
          'Dialog Set Timer Callback_Handle, %IDC_TIMER, %TIMER_DELAY
          'Dialog Set Timer Callback_Handle, %IDC_TIMER, %PICCANVAS
          'Dialog Set Timer CBHNDL, %tAnimationTimer, 10, %NULL     
          
    '  Select Case CBMSG
        Case %WM_COMMAND
          If CBWPARAM = %ButtonClose Then Dialog End CBHNDL
        
        Case %WM_DESTROY
      End Select 
    End Function
    '------------------- not in use ----------------------------------- >
    CallBack Function refreshProc() As Long
       Static picGameStarted As Byte
    ' -- Refresh button   
      If CBMSG = %WM_COMMAND Then     
        If CBCTLMSG = %BN_CLICKED Then
         
          Dialog Kill Timer CBHNDL, %tAnimationTimer
          Dialog Set Timer CBHNDL, %tAnimationTimer, 1000, %NULL     
          picGameStarted = 1
      
        End If
      End If
      
    End Function 
    '------------------- not in use ----------------------------------- >
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~> not in use at moment ~~~~~>
    CallBack Function PicsMoveProc() As Long
    '------------------------------------------>
      Local PicsLabel As String                 
      Local hdlgz As Long
    '
      If CBMSG = %WM_COMMAND And CBCTLMSG = %BN_CLICKED Then
        If CBCTL-1 >=  %PICSTARTS Then
          Control Get Text CBHNDL, CBCTL-1 To PicsLabel      
          If PicsLabel = "0" Then
            MovePic CBHNDL,CBCTL- 1,CBCTL      
          End If
        End If
        
        If  CBCTL+1 < %PICSTARTS + %NumberofPics*%NumberofPics Then
          Control Get Text CBHNDL, CBCTL+1 To PicsLabel 
          Control Get Text hwnd, ctrlID To txtVarName
          If PicsLabel = "0" Then
            MovePic CBHNDL,CBCTL+1,CBCTL        
          End If
        End If
        If  CBCTL-%NumberofPics >= %PICSTARTS Then
          Control Get Text CBHNDL, CBCTL-%NumberofPics To PicsLabel
          If PicsLabel = "0" Then
            MovePic CBHNDL,CBCTL-%NumberofPics,CBCTL        
          End If
        End If
        If CBCTL+%NumberofPics < %PICSTARTS + %NumberofPics*%NumberofPics Then
          Control Get Text CBHNDL, CBCTL+%NumberofPics To PicsLabel
          If PicsLabel = "0" Then
            MovePic CBHNDL,CBCTL+%NumberofPics,CBCTL        
          End If
        End If
    '
      End If
    '
    End Function                                               
    ' -- Stop button
    CallBack Function stopProc()
      
      If CBMSG = %WM_COMMAND Then     
        If CBCTLMSG = %BN_CLICKED Then
         
          Dialog Kill Timer CBHNDL, %tAnimationTimer
          
        End If
      End If
      
    End Function
    

    bye, largo
    Attached Images Attached Images

  6. #16
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi,

    I would recommend to start with data structure - design a TYPE, which would describe X, Y, Width, Height and bitmap of each tile.
    Then you could make array of this TYPE to hold info about all the tiles you have.

    Then you can use Canvas_BitmapRender with optional parameters X1, Y1, X2, Y2 to draw individual pieces into single canvas.

    Then, to handle clicks, you could just have one handler routine for whole canvas, and based on place of click determine which tile was clicked by looking up to tile coordinates and dimensions stored in array.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  7. #17
    thanks for your help and good tipp petr! I will check for another part of my not-ready-game project next time.

    (deleted next question)


    bye, largo
    Last edited by largo_winch; 07-02-2013 at 19:21.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Animation within a Callback
    By marcuslee in forum thinBasic General
    Replies: 2
    Last Post: 03-09-2010, 16:57
  2. spider animation (again)
    By zak in forum TBGL General
    Replies: 4
    Last Post: 18-07-2010, 11:14
  3. Sprites / Character animation
    By Petr Schreiber in forum TBGL Tutorials
    Replies: 3
    Last Post: 22-12-2009, 10:20
  4. MD2 Animation
    By Petr Schreiber in forum TBGL General
    Replies: 8
    Last Post: 05-08-2008, 06:06
  5. bitmap font
    By kryton9 in forum TBGL General
    Replies: 6
    Last Post: 26-04-2007, 20:53

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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