Sub Process_Globals
Public NavControl As NavigationController
Private Page1 As Page
Private panel1 As Panel
Private cvs As Canvas
Private timer1 As Timer
Private bmp As Bitmap
Private currentX, currentY, vx = 10, vy = 10 As Float
Private smileySize As Float = 50
End Sub
Private Sub Application_Start (Nav As NavigationController)
NavControl = Nav
Page1.Initialize("Page1")
Page1.Title = "Smiley Example"
NavControl.ShowPage(Page1)
panel1.Initialize("panel1")
Page1.RootPanel.AddView(panel1, 0, 0, 100%x, 100%y)
bmp.Initialize(File.DirAssets, "smiley.png")
timer1.Initialize("timer1", 30)
timer1.Enabled = True
End Sub
Private Sub Page1_Resize(Width As Int, Height As Int)
CreateBackground
panel1.SetLayoutAnimated(0, 0, 0, 100%x, 100%y)
cvs.Release
cvs.Initialize(panel1)
cvs.DrawColor(Colors.Transparent)
cvs.Refresh
End Sub
Sub CreateBackground
'create the gradient background
Dim c As Canvas
c.Initialize(Page1.RootPanel)
c.FillGradient(0, 0, 100%x, 100%y, Array(Colors.LightGray, Colors.DarkGray))
c.Refresh
c.Release
End Sub
Sub Panel1_Touch(Action As Int, X As Float, Y As Float)
If Action = panel1.ACTION_DOWN Then
cvs.DrawCircle(X, Y, 10, 0xAFFF0000, True, 0)
If X >= currentX AND X <= currentX + smileySize AND Y >= currentY AND Y <= currentY + smileySize Then
vx = -vx
vy = -vy
End If
cvs.Refresh
End If
End Sub
Sub Timer1_Tick
Dim r As Rect
r.Initialize(currentX, currentY, currentX + smileySize, currentY + smileySize)
cvs.DrawRect(r, Colors.Transparent, True, 0)
If currentX + smileySize > cvs.View.Width Then
vx = -Abs(vx)
Else If currentX < 0 Then
vx = Abs(vx)
End If
If currentY + smileySize > cvs.View.Height Then
vy = -Abs(vy)
Else If currentY < 0 Then
vy = Abs(vy)
End If
currentX = currentX + vx
currentY = currentY + vy
r.Initialize(currentX, currentY, currentX + smileySize, currentY + smileySize)
cvs.DrawBitmap(bmp, r)
cvs.Refresh
End Sub