VirtualControlRect control,anchor,x#,y#,width#,height#
Parameters
| anchor: 1 top-left, 2 top-right, 3 bottom-left, 4 bottom-right, 5 center. Other values are logical display units. |
Description
Sets custom geometry after cancelling the contact. Corner offsets are positive inward and locate the matching rectangle corner; center offsets move its center right/down. Width/height must be positive and values finite. Group scale applies; the final rectangle is clamped inside the safe area. Preserve enough spacing when adding multiple controls.
Native overlays are supported on iOS, Android, macOS and Windows, including IDE run presets and saved layouts, and on the web, where the page draws them over the canvas. Controls use presentation coordinates, remain responsive during blocking input waits, and are excluded from SaveBuffer. See the mobile input guide. |
; VirtualControlRect Example
; Virtual keyboard: movement and action use only existing keyboard commands.
Graphics 800,480,0,2
SetBuffer BackBuffer()
Local keys=CreateVirtualKeyboard("wasd")
If keys=0 Then RuntimeError MobileInputError$()
control=VirtualControl(keys,"space")
VirtualControlRect control,4,20,20,120,56
Local x#=400,y#=210,score=0,target_x#=530,target_y#=200
Local previous=MilliSecs()
While Not KeyHit(1)
Local now=MilliSecs(),dt#=Float(now-previous)/1000
previous=now
If dt<0 Then dt=0
If dt>0.05 Then dt=0.05
x=x+(KeyDown(32)-KeyDown(30))*180*dt
y=y+(KeyDown(31)-KeyDown(17))*180*dt
If x<15 Then x=15
If x>785 Then x=785
If y<85 Then y=85
If y>465 Then y=465
If KeyHit(57)
If (x-target_x)^2+(y-target_y)^2<65^2
score=score+1
target_x=Rnd(180,610)
target_y=Rnd(120,280)
EndIf
EndIf
If KeyHit(28) Then score=0
Cls
Color 255,255,255
Text 20,48,"Move with WASD; press Space near the gold target. Score: "+score
Text 20,68,"Enter resets. Esc exits. Controls opens layout options; drag its tab to move it."
Color 255,200,40
Oval target_x-15,target_y-15,30,30,True
Color 70,200,255
If KeyDown(57) Then Color 255,255,255
Oval x-12,y-12,24,24,True
Flip
Wend
FreeVirtualControls keys
End
Open example ยท Command index