#Region Project Attributes
#MainFormWidth: 500
#MainFormHeight: 500
#End Region
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private cnv As B4XCanvas
'Private redBall As B4XBitmap
Private xui As XUI
Private timer As Timer
Private vpw, vph As Float
Private speedx As Float = 0
Private speedy As Float = 0
Private leftPos As Float
Private topPos As Float
Dim ballradius As Float
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
MainForm.Show
vpw = MainForm.RootPane.Width
vph = MainForm.RootPane.Height
cnv.Initialize(MainForm.RootPane)
' redBall = xui.LoadBitmap(File.DirAssets,"redball.png")
leftPos = -vpw
topPos = -vph
timer.Initialize("timer",1000/60)
timer.Enabled = True
End Sub
Sub timer_Tick
clearcnvblackbackground
drawballwithpattern
End Sub
Sub clearcnvblackbackground
cnv.ClearRect(cnv.TargetRect)
cnv.DrawRect(returnRect(0,0,vpw,vph),xui.Color_Black,True,0)
End Sub
Sub drawparallexbackground
leftPos = leftPos - speedx
topPos = topPos - speedy
ballradius = vpw*0.3
Dim color As Int = xui.Color_Red
cnv.DrawRect(returnRect(0,0,vpw,vph),color,True,0)
For x = 0 To 3
For y = 0 To 4
'CREATE SHADOW
Dim alphaLevel As Float = 30
Dim radiusIncrease As Float = ballradius
For s = 0 To 10
cnv.DrawCircle((leftPos+(x*vpw)),topPos+(y*vph)+(vph/2),radiusIncrease,xui.Color_ARGB(alphaLevel,0,0,0),True,0)
alphaLevel = Max(alphaLevel-3, 0)
radiusIncrease = radiusIncrease * 1.05
Next
cnv.DrawCircle((leftPos+(x*vpw)),topPos+(y*vph)+(vph/2),ballradius,xui.Color_White,True,0)
Next
Next
If leftPos <= -vpw*2 Then leftPos = -vpw
If topPos <= -vph*2 Then topPos = -vph
If leftPos >= 0 Then leftPos = -vpw
If topPos >= 0 Then topPos = -vph
End Sub
Sub drawballwithpattern
Dim ballshape As B4XPath
ballshape.InitializeOval(returnRect((vpw/2)-150,(vph/2)-150,300,300))
cnv.ClipPath(ballshape)
drawparallexbackground
cnv.RemoveClip
End Sub
Sub returnRect(x As Float, y As Float, w As Float, h As Float) As B4XRect
Dim r As B4XRect
r.Initialize(x,y,x+w,y+h)
Return r
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub MainForm_MouseMoved (EventData As MouseEvent)
If EventData.X > vpw*0.55 Then
speedx = -3
else if EventData.X < vpw*0.45 Then
speedx = 3
Else
speedx = 0
End If
If EventData.y < vph*0.45 Then
speedy = 3
else if EventData.y > vph*0.55 Then
speedy = -3
Else
speedy = 0
End If
End Sub