hi
i would like to know if there is a huge performance difference if i would use "drawpath WITH clippath" or use drawbitmap instead?
it is about a new game i am working on. from tesst i did i get less than 1ms for the whole drawing process which keeps me without any problem on 60 fps.
what i do is i draw the canvas > then clippath a specific area > then return the bitmap of the canvas and use it.
i don't like this way to get a bitmap, is there a better solution? this process is done 16 times each Tick (60 updates in 1 second so within about 16ms)
if it will stay under 1ms it is fine and this is the result i get in debug mode.
any other way to create a bitmap that may be faster?
this is the relevant code:
how can i improve this code to make it run faster?
thanx
i would like to know if there is a huge performance difference if i would use "drawpath WITH clippath" or use drawbitmap instead?
it is about a new game i am working on. from tesst i did i get less than 1ms for the whole drawing process which keeps me without any problem on 60 fps.
what i do is i draw the canvas > then clippath a specific area > then return the bitmap of the canvas and use it.
i don't like this way to get a bitmap, is there a better solution? this process is done 16 times each Tick (60 updates in 1 second so within about 16ms)
if it will stay under 1ms it is fine and this is the result i get in debug mode.
any other way to create a bitmap that may be faster?
this is the relevant code:
B4X:
Private Sub drawballwithpattern As B4XBitmap
cnv.ClearRect(cnv.TargetRect)
Dim ballshape As B4XPath
ballshape.InitializeOval(returnRect(0,0,ballWidth,ballHeight))
cnv.ClipPath(ballshape)
drawparallexbackground(senderBall.body.Velocity)
cnv.RemoveClip '<---- is this necessary???
Dim bmp As B4XBitmap = cnv.CreateBitmap
cnv.Release '<---- is this necessary???
Return bmp
End Sub
Private Sub drawparallexbackground(velocity As Vector)
Private speedx As Float = -Functions.mapping(velocity.Dx,0,4000,0,80)
Private speedy As Float = Functions.mapping(velocity.Dy,0,2000,0,40)
leftPos = leftPos - speedx
topPos = topPos - speedy
ballradius = ballWidth*0.45
cnv.DrawRect(returnRect(0,0,ballWidth,ballHeight),senderBall.colorint,True,0)
For x = 0 To 3
For y = 0 To 2
Dim px As Float = leftPos+(x*(ballWidth*1.5))
Dim py As Float = topPos+(y*(ballHeight*1.5))+(ballHeight/2)
If senderBall.fullcolor = False Then
cnv.DrawCircle(px,py,ballradius,xui.Color_White,True,1)
cnv.DrawCircle(px+(ballWidth*0.75),py+(ballWidth*0.75),4.5,xui.Color_White,True,1)
cnv.DrawText(senderBall.number,px+(ballWidth*0.75),py+(ballWidth*0.75)+2,xui.CreateDefaultBoldFont(6),xui.Color_Black,"CENTER")
Else
If senderBall.number > 0 Then
cnv.DrawCircle(px+(ballWidth/2),py,4.5,xui.Color_White,True,1)
cnv.DrawText(senderBall.number,px+(ballWidth/2),py+2,xui.CreateDefaultBoldFont(6),xui.Color_Black,"CENTER")
Else
If x = 1 Then cnv.DrawCircle(px+(ballWidth/2),py,2,xui.Color_Red,True,1)
End If
End If
Next
Next
If leftPos <= -ballWidth*3 Then leftPos = ballWidth*3
If topPos <= -ballWidth*3 Then topPos = ballWidth*3
If leftPos >= 0 Then leftPos = -ballWidth*1.5
If topPos >= 0 Then topPos = -ballWidth*1.5
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
how can i improve this code to make it run faster?
thanx