Main Menu

Display Messages

Started by kevin, November 12, 2009, 09:15:35 PM

Previous topic - Next topic

kevin

 Here's a little example system that allow you to post messages and display them as part of your refresh..

PlayBASIC Code: [Select]
   SetFPS 30

Type tMessage
x,y ; screen position
Dizzy$
Colour
EndOFDisplayTime
EndType

Dim Message as tMessage List


; A message in the center of the default screen. This message will say HELLO WORLD
; and be on screen for at least 10000 milliseconds.. (10 seconds for us humans)
AddNewMessage(400,300,"Hello World",10000)



; -------------------------------------------------
Do ; Programs Main Loop
; -------------------------------------------------

cls rgb(0,0,0)

; press space to random add another message
if spacekey()


x =rnd(800)
y =rnd(600)
Dizzy$ ="This is a message"
TimeToDisplay =rndrange(500,2000) ; diusplay time between 1/2 a second and 2 seconds

; Add this message
AddNewMessage(x,y,Dizzy$,TimeToDisplay)

endif


; render the messages
DrawMessages()

Sync

loop



Function AddNewMessage(x,y,Dizzy$,TimeToDisplay)

; add a new item to the message list
Message= new tMessage

; set iut's properties
Message.x =x
Message.y =y
Message.Dizzy$ =Dizzy$

message.EndOFDisplayTime = timer() +TimeToDisplay
Message.colour =rndrgb()

EndFunction


Function DrawMessages()
oldInk=getInk()
CurrentTime=timer()
for each Message()
if CurrentTime<message.EndOFDisplayTime
ink Message.colour
centertext message.x,message.y,message.dizzy$
else
Message = null
endif
next
ink oldink
EndFunction