Im trying to create a bouncing ball demo to test performance graphically (without physics) using only the forms paint method but adding more than 4 balls makes it incredibly slow on the ppc, can anyone suggest an optimal way to loop through the ball properties, I know that using the sprite library might help but I wanted to get the best performance first out of just raw code and the form methods.
Here it is:-
Here it is:-
B4X:
'Program: Program to demonstrated the speed of the fill rountine for forms
' several bouncing balls with no physics.
Sub Globals
'Declare the global variables here.
QUIT =False
' balls coordinates are in array
' hence Ball(n,(xpos,ypos,xspeed,yspeed),) n= number of balls
NumBalls=3
Dim Balls(NumBalls,4)
'Setup balls
For i=0 To ArrayLen(balls(),1) -1
balls(i,0)=Rnd(100,200) 'xpos
balls(i,1)=Rnd(100,250) 'ypos
balls(i,2)=Rnd(-10,6) 'xspeed
balls(i,3)=Rnd(-10,7) 'yspeed
Next i
End Sub
Sub App_Start
Canvas.Show
timer1.Interval=20
timer1.Enabled=True
'Msgbox("End")
End Sub
Sub Timer1_Tick
For i=0 To ArrayLen(balls(),1) -1
canvas.Circle(balls(i,0),balls(i,1),10,0,0,0,f)
balls(i,0)=balls(i,0)+balls(i,2)
balls(i,1)=balls(i,1)+balls(i,3)
If balls(i,0)>(220-5) Then
balls(i,2)=-balls(i,2)
balls(i,1)=balls(i,1)+Rnd(0,3)
End If
'If balls(i,2)=balls(i,3) Then
'balls(i,2)=Rnd(balls(i,2),3) 'randomize if 'speeds equal out
'balls(i,3)=Rnd(balls(i,3),3)
'End If
If balls(i,1)>(250-5) Then
balls(i,3)=-balls(i,3)
balls(i,0)=balls(i,0)+Rnd(0,3)
End If
If balls(i,0) <10 Then balls(i,2)=-balls(i,2)
If balls(i,1) <10 Then balls(i,3)=-balls(i,3)
If balls(i,1)=250-5 Then balls(i,1)=balls(i,1)-1
If balls(i,1)=10 Then balls(i,1)=balls(i,1)+1
If balls(i,0)>260 OR balls(i,0)<-50 Then balls(i,2)=0 'kill ball if it ventures off
If balls(i,1)>400 OR balls(i,1)<-100 Then balls(i,3)=0
canvas.Circle(balls(i,0),balls(i,1),10,Rnd(10,255),Rnd(10,255),Rnd(10,255),f)
Next i
End Sub