Draw Text and move with arrow keys
Posted: Thu Apr 02, 2009 12:04 pm
I am having trouble drawing text on the screen and using arrow keys to move it up or down.
So near but yet so far..
So near but yet so far..
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
xx = 140:yy = 120
If InitSprite() And InitKeyboard() And OpenScreen(800,600,16,"")
Repeat
FlipBuffers()
ClearScreen(RGB(0, 0, 0))
ExamineKeyboard()
Title$ = "XXXXXXXXXXXXXX"
If KeyboardPushed(#PB_Key_Down)
xx + 2
EndIf
If KeyboardPushed(#PB_Key_Up)
xx - 2
EndIf
If KeyboardPushed(#PB_Key_Right)
yy + 3
EndIf
If KeyboardPushed(#PB_Key_Left)
yy - 3
EndIf
; Display the result
;
If StartDrawing(ScreenOutput())
DrawingMode(1)
FrontColor(RGB(128, 255, 0))
DrawText(yy, xx, Title$)
StopDrawing()
EndIf
Until KeyboardPushed(#PB_Key_Escape)
EndIf
Code: Select all
xx = 140:yy = 120
If InitSprite() And InitKeyboard() And OpenScreen(800,600,16,"")
Title$ = "XXXXXXXXXXXXXX"
Repeat
FlipBuffers()
ClearScreen(RGB(0, 0, 0))
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Down)
xx + 2
EndIf
If KeyboardPushed(#PB_Key_Up)
xx - 2
EndIf
If KeyboardPushed(#PB_Key_Right)
yy + 3
EndIf
If KeyboardPushed(#PB_Key_Left)
yy - 3
EndIf
Title$ + KeyboardInkey()
; Display the result
;
If StartDrawing(ScreenOutput())
DrawingMode(1)
FrontColor(RGB(128, 255, 0))
DrawText(yy, xx, Title$)
StopDrawing()
EndIf
Until KeyboardPushed(#PB_Key_Escape)
EndIf
Code: Select all
xx = 140:yy = 120
If InitSprite() And InitKeyboard() And OpenScreen(800,600,16,"")
Title$ = "XXXXXXXXXXXXXX"
Repeat
FlipBuffers()
ClearScreen(RGB(0, 0, 0))
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Down)
CountDown = 10
vy = 2
EndIf
If KeyboardPushed(#PB_Key_Up)
CountDown = 10
vy = - 2
EndIf
If KeyboardPushed(#PB_Key_Right)
CountDown = 10
vx = 2
EndIf
If KeyboardPushed(#PB_Key_Left)
CountDown = 10
vx = - 2
EndIf
If CountDown
CountDown - 1
xx + vx
yy + vy
Else
vx = 0
vy = 0
EndIf
Title$ + KeyboardInkey()
; Display the result
;
If StartDrawing(ScreenOutput())
DrawingMode(1)
FrontColor(RGB(128, 255, 0))
DrawText(xx, yy, Title$)
StopDrawing()
EndIf
Until KeyboardPushed(#PB_Key_Escape)
EndIf
Code: Select all
Macro Draw()
If StartDrawing(SpriteOutput(#StringTestSpr))
DrawingMode(0)
Box(0, 0, SpriteWidth(#StringTestSpr), SpriteHeight(#StringTestSpr), RGB(0, 0, 0) )
DrawText(8, 8, Title$, RGB(128, 255, 0), RGB(0, 0, 0) )
StopDrawing()
EndIf
DisplaySprite(#StringTestSpr, xx, yy)
Delay(1)
FlipBuffers()
EndMacro
#StringTestSpr = 1
xx = 140:yy = 120
If InitSprite()
If InitKeyboard()
If OpenScreen(800,600,16,"")
CreateSprite(#StringTestSpr, 256, 32)
Title$ = "XXXXXXXXXXXXXX"
ClearScreen(RGB(0, 0, 0))
Draw()
Repeat
Delay(1)
If ExamineKeyboard()
CharKey$ = KeyboardInkey()
If CharKey$
Title$ + CharKey$
Draw()
EndIf
If KeyboardPushed(#PB_Key_Back)
If BackKey = 0
BackKeyStart = ElapsedMilliseconds()
EndIf
If (BackKey = 0) Or ((ElapsedMilliseconds() - BackKeyStart) > 600)
If Title$
Title$ = Left(Title$, Len(Title$) - 1)
EndIf
Draw()
EndIf
BackKey + 1
Else
BackKey = 0
EndIf
If KeyboardPushed(#PB_Key_Down)
CountDown = 10
vy = 2
EndIf
If KeyboardPushed(#PB_Key_Up)
CountDown = 10
vy = - 2
EndIf
If KeyboardPushed(#PB_Key_Right)
CountDown = 10
vx = 2
EndIf
If KeyboardPushed(#PB_Key_Left)
CountDown = 10
vx = - 2
EndIf
If KeyboardPushed(#PB_Key_Escape)
Break
EndIf
EndIf
If CountDown
xx + vx
yy + vy
CountDown - 1
If CountDown <= 0
vx = 0
vy = 0
EndIf
Draw()
EndIf
ForEver
EndIf
EndIf
EndIf