Register    Login    Forum    FAQ    PinSimDB.org

Board index » Resources » Tutorials, how-to's, bug report and docs




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: How to Create an Animated DMD
 Post Posted: Sat Mar 02, 2019 11:15 am 
Offline

Joined: Thu Aug 16, 2012 11:12 pm
Posts: 2407
Location: Arkansas, USA
This tutorial is created from the posting at:

viewtopic.php?f=15&t=8795

Slamt1lt had this old video which uses image lists and overlays for dmd:

https://youtu.be/j3Z6WBHXV6U

And this
https://youtu.be/Sg6N_Bjq8Vk

And this
https://youtu.be/7ER4w0kWJxs

- DMDPaint http://ainc.de/
- Gfx2Dmdf http://www.pinsimdb.org/pinres/index-10-future_pinball?searchTitle=gfx2dmdf&searchType=-1&searchSubtype=-1&searchAuthor=&searchAuthorIdx=-1

From Francisco666:

What I have done in my little experience:

Fonts:
* Hand redraw dot by dot all fonts and numbers using FP DMD font editor, take in mind that the font MUST include the separation in between letters, usually is a dot.-
* Diferent fonts for diferent size.-

Using images:
* If you going to use a image, a .png is recommended and your font must be 128 x 32 pxs for most comon DMD in a grey scale like:

download/file.php?id=7473

* If you use DMD Paint, ALWAYS keep the .txt as backup since you can't edit the .dmdf


Table implementation:

Basics:
The way we use the fonts in FP is this:

-You have a set of fonts:
ABCDEFGH.........

And each letter is a frame of the DMD animation:

Lets say that the animation has 4 frames, we save each frame in a single letter. It doesn't matter which ones since you going to use all the letters and symbol, like this:

Image

So what we going to do is script something so the DMD show the letters a,b,c,d in the DMD

So the DMD looks like this:

download/file.php?id=7474

next scripting a DMD

My code, have thing grabbed from Glxb code, I will paste here and explain it

Code:


'*************************************************************************************************************
'*************************************************************************************************************
'******************************************************** D M D ********************************************************
function RandomNumber(ByVal max)
   RandomNumber = Int(max * Rnd + 1)
end function

            sub stopdmds
               TimerDMD.Enabled = false                
               TimerDMD2.Enabled = false                
               Timeraddzero.Enabled = false
            end sub
'DMD

' *****dmd tHIngS
dim dmdstring
Dim PrimerLetra
Dim UltimaLetra
Dim Fuente
Dim Dmdinuse
dim velocidad
DIM textstring
dim atractcount
dim mantener


dim showingjackpot
DIM dmdinuselow

'MODELO
sub Target100000_hit
PrimerLetra=32
UltimaLetra=125
fuente =1
velocidad=50
textstring="[f1] "
mantener=10
empiezadmd
end sub



Sub empiezadmd
   TimerDMD2.Enabled = false
   TimerDMD.Enabled = false
   TimerDMD.Interval = velocidad
   Timeraddzero.Enabled = False   
   TimerDMD.Enabled = True
   Dmdinuse=true
   if showingjackpot=true then
      exit sub
   end if
end sub


sub TimerDMD_expired()
                        'AddDebugText "timer exp"
                        'AddDebugText ""&PrimerLetra   
   TimerDMD.Enabled = false
   PrimerLetra = PrimerLetra + 1
   dmdstring = "[f"+cstr(fuente)+"][xc][yc]" &chr(PrimerLetra) &"[f1] "&textstring
   MyDmd.Text=dmdstring
   MyDMD2.Text=dmdstring
   if (PrimerLetra => UltimaLetra) then    
      'AddDebugText "to zero"

      
      TimerDMD.Enabled = false
      Timeraddzero.Interval = mantener
      Timeraddzero.Enabled = true
      
      exit sub   
   end if
   TimerDMD.Interval = velocidad
   TimerDMD.Enabled = True
end sub


sub Timeraddzero_expired
      'AddDebugText "dmd libre"
      textstring="[f1]"
      Timeraddzero.Enabled = False   
      Dmdinuse=false
      dmdinuselow=false
      showingjackpot=false
      bumpersindisp=false
      MyDMD.FlushAnimation
      MyDMD.FlushQueue   
      MyDMD2.FlushAnimation
      MyDMD2.FlushQueue         
      addscore(0)
end sub





Sub empiezadmd2
   if dmdinuse=true then
      exit sub
   end if
   TimerDMD2.Enabled = false
   TimerDMD2.Interval = velocidad
   Timeraddzero.Enabled = False   
   TimerDMD2.Enabled = True
   Dmdinuselow=true
end sub

sub TimerDMD2_expired()
                        'AddDebugText "timer exp"
                        'AddDebugText ""&PrimerLetra   
   TimerDMD2.Enabled = false
   PrimerLetra = PrimerLetra + 1
   dmdstring = "[f1] "&textstring &"[f"+cstr(fuente)+"][xc][yc]" &chr(PrimerLetra)
   MyDmd.Text=dmdstring
   MyDMD2.Text=dmdstring
   if (PrimerLetra => UltimaLetra) then    
   '   AddDebugText "to zero"
      TimerDMD2.Enabled = false
      Timeraddzero.Interval = mantener
      Timeraddzero.Enabled = true
      exit sub   
   end if
   TimerDMD2.Interval = velocidad
   TimerDMD2.Enabled = True
end sub





Function FormatScore(num)
    Dim n, f, s
    n = CStr(num)
    f = ""
       
    do while len(n)>3
        if len(f)>0 then
            f = Right(n, 3) & "," & f
        else
            f = Right(n, 3)
        end if
        n = Left(n, Len(n)-3)
    loop
    if len(n)>0 then
        if len(f) > 0 then
            f = n & "," & f
        else
            f = n
        end if
    end if
    FormatScore = f
End Function


This part, as the name says, stops all dmds

The DMD works with 2 timers, one that will change the font after it expires if there is a font next, and one that will add 0 points when the last frame (letter) is show, because if not the DMD will stick with the last frame

In the code, are 2 DMD timers (TimerDMD and TimerDMD2) because tables usually have a prioritization about what display on the DMD if 2 animations come. The Jackpot is the usually example of that, lets say that the bumpers have a animation when hit and suddenly you hit a Jackpot, the Jackpot DMD animation cant be stopped, there are a lot of prioritization on pinball tables

Code:
            sub stopdmds
               TimerDMD.Enabled = false                
               TimerDMD2.Enabled = false                
               Timeraddzero.Enabled = false
            end sub


The following is a basic instruction for a DMD animation that use the script below:

Code:
'MODELO
sub Target100000_hit
PrimerLetra=32
UltimaLetra=125
fuente =1
velocidad=50
textstring="[f1] "
mantener=10
empiezadmd
end sub


Lets see line per line

sub Target100000_hit
Well a target been hit hahaahah :lol:


PrimerLetra=32
Set the first letter by number of the character, in this case 32

The number corresponds with the Character number, 32 is the space bar, 33 is !, see the FP DMD editor to know what number is what character


UltimaLetra=125
Set the last letter by number of the character, in this case 125

The number correspon with the Character number 125 ia }

fuente =1
Font number assigned in script using AddFont, in this case 1

MyDMD.AddFont 1, "The font name"

velocidad=50
The speed in wich the DMD animation change from frame to frame, high value slow animation, low values fast animations, its measure in milliseconds and is the timer duration of TimerDMD


textstring="[f1] "
Sometimes DMD animations have txt on it, so there is when you add the text

mantener=10
Hold the last frame at the DMD before back to show score, is used milliseconds

empiezadmd
call the subrutine sub empiezadmd to start the DMD animation

lets see...

Code:
Sub empiezadmd
   TimerDMD2.Enabled = false
   TimerDMD.Enabled = false
   TimerDMD.Interval = velocidad
   Timeraddzero.Enabled = False   
   TimerDMD.Enabled = True
   Dmdinuse=true
   if showingjackpot=true then
      exit sub
   end if
end sub


First stop all the timers and adjust the timer new speed
TimerDMD2.Enabled = false
TimerDMD.Enabled = false
TimerDMD.Interval = velocidad
Timeraddzero.Enabled = False



Start the timer again
TimerDMD.Enabled = True

Set a flag that tell us that the DMD is in use, used for no points refresh, see last msj
Dmdinuse=true


Do nothing if jackpot are in DMD, must be un top of the subrutine, at the botton dosent have any effect
if showingjackpot=true then
exit sub
end if


Finally:

Code:
sub TimerDMD_expired()
                        'AddDebugText "timer exp"
                        'AddDebugText ""&PrimerLetra   
   TimerDMD.Enabled = false
   PrimerLetra = PrimerLetra + 1
   dmdstring = "[f"+cstr(fuente)+"][xc][yc]" &chr(PrimerLetra) &"[f1] "&textstring
   MyDmd.Text=dmdstring
   MyDMD2.Text=dmdstring
   if (PrimerLetra => UltimaLetra) then    
      'AddDebugText "to zero"

      
      TimerDMD.Enabled = false
      Timeraddzero.Interval = mantener
      Timeraddzero.Enabled = true
      
      exit sub   
   end if
   TimerDMD.Interval = velocidad
   TimerDMD.Enabled = True
end sub


In the main TimerDMD subroutine after the clock expires according to velocidad, the speed of the animation, the character will be go to the next one:
PrimerLetra = PrimerLetra + 1

Characters are numbers

And if we reach the last font
if (PrimerLetra => UltimaLetra) then

Stop all and set the timer to add cero points to go back to point
Timeraddzero.Interval = mantener
Timeraddzero.Enabled = true


IMPORTANT

You must add some lines to your routine of adding points, by default it is
Sub AddScore(points)

After the math of adding points
nvScore(CurrentPlayer) = nvScore(CurrentPlayer) + (Points)

add
Code:
   if dmdinuse=true then
      exit sub
   end if


If you don't, the DMD will flicker

Well sorry my English, hope it can be understand somehow, and I'm here to answer any question.


Top 
 Profile  
 
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 1 post ] 

Board index » Resources » Tutorials, how-to's, bug report and docs


Who is online

Users browsing this forum: No registered users and 1 guest

 
 

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to: