'Code module
Sub Process_Globals
Private cnv As B4XCanvas
Private xui As XUI
Private ballWidth, ballHeight As Float
Private ballradius As Float
Private ballColor As Int
Private leftPos As Float
Private topPos As Float
Private senderBall As ball
End Sub
Public Sub returnTexture(ballPnl As Panel, myball As ball) As SKTexture
cnv.Initialize(ballPnl)
senderBall = myball
ballWidth = myball.Width
ballHeight = myball.Height
leftPos = myball.left
topPos = myball.top
' Log(speedx & ":" & speedy)
ballColor = myball.colorint
Dim texture As SKTexture
texture.Initialize
texture.TextureWithImage(drawballwithpattern(myball.body.Velocity))
ballPnl.RemoveAllViews
Return texture
End Sub
Private Sub drawballwithpattern(velocity As Vector) As B4XBitmap
cnv.ClearRect(cnv.TargetRect)
Dim ballshape As B4XPath
ballshape.InitializeOval(returnRect(0,0,ballWidth,ballWidth))
cnv.ClipPath(ballshape)
drawparallexbackground(velocity)
cnv.RemoveClip
Return cnv.CreateBitmap
End Sub
Private Sub drawparallexbackground(velocity As Vector)
Private speedx As Float = 0
Private speedy As Float = 0
speedx = -Functions.mapping(velocity.Dx,0,1000,0,10)
speedy = Functions.mapping(velocity.Dy,0,1000,0,10)
leftPos = leftPos - speedx
topPos = topPos - speedy
ballradius = ballWidth*0.25
cnv.DrawRect(returnRect(0,0,ballWidth,ballHeight),ballColor,True,0)
For x = 0 To 3
For y = 0 To 3
cnv.DrawCircle((leftPos+(x*ballWidth)),topPos+(y*ballHeight)+(ballHeight/2),ballradius,xui.Color_White,True,1)
Next
Next
If leftPos <= -ballWidth*2 Then leftPos = -ballWidth
If topPos <= -ballHeight*2 Then topPos = -ballHeight
If leftPos >= 0 Then leftPos = -ballWidth
If topPos >= 0 Then topPos = -ballHeight
senderBall.left = leftPos
senderBall.top = topPos
End Sub
Private 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