I still have no idea how to program a game with the library/framework.
I have programmed this game with normal B4x code, but it doesn't look so good, the balls don't run so smoothly (see video).
Which library/framework could you recommend me, or which library is easier to learn?
In the video the balls runs ok. I dont see something wrong with the animation and if thats the whole animation you want to archive then i would not use any library for that.
just use canvas but draw only the balls every frame. The background and everything that does not change draw ones u can use multiple panles like layers.
EDIT: v1.02 update. Tided up the code Hi folks A Snooker/Billards simulation for Basic4Android This example is fully operational although there is no code to "pot" a ball All you can do here is aim and shoot. Its enough to get you going though INSTRUCTIONS # Touch / Move finger on the table...
www.b4x.com
I simply rotate the balls with this code:
B4X:
Sub RenderPanel2(grad As Int)
Dim dRect As Rect
can2.DrawColor(Colors.Transparent)
For i=0 To NUMBALLS
dRect.Initialize(ball(i).x - BALL_RADIUS, ball(i).y - BALL_RADIUS,ball(i).x + BALL_RADIUS, ball(i).y + BALL_RADIUS)
bmpBallClosed = bmpBallClosed.Rotate(grad)
can2.DrawBitmap(bmpBallClosed, Null, dRect)
Next
pan2.Invalidate
End Sub
Rotating in itself is not a problem.
Even if you remove this rotation, the animation, in my opinion, does not look so good.
Therefore I ask myself if with the use of a library, the animation can be better.
Thank you very much Ilan!
Your new animation looks good, runs much smoother than the old one.
The thing that is still missing is the collision between the balls, I hope I can implement it myself.
Thank you very much Ilan!
Your new animation looks good, runs much smoother than the old one.
The thing that is still missing is the collision between the balls, I hope I can implement it myself.
i also implemented it in another example but did not include it because it had some bugs and i didnot want to spent to much time.
anyway, you already have a collision detection in the code to check if the balls are away from each other to stop them.
so you just need to change the direction when the distance between the balls are smaller then the ball radius
try this "moveballs" function instead of the one in the example above:
B4X:
Private Sub moveballs
For Each b As ball In ballsList
b.x = b.x + b.xSpeed
b.y = b.y + b.ySpeed
b.angle = b.angle + (b.xSpeed*2)
If b.x+(b.r/2) >= vpW Or b.x-(b.r/2) <= 0 Then b.xSpeed = b.xSpeed * -1
If b.y+(b.r/2) >=vpH Or b.y-(b.r/2) <= 0 Then b.ySpeed = b.ySpeed * -1
Next
'Collision detection between balls
For i = 0 To ballsList.Size-1
Dim b As ball = ballsList.Get(i)
For j = 0 To ballsList.Size-1
Dim b2 As ball = ballsList.Get(j)
If b.id = b2.id Then Continue 'skip same ball
If distance(b.x,b2.x,b.y,b2.y) <= b.r Then
b.xSpeed = b.xSpeed * -1
b.ySpeed = b.ySpeed * -1
b2.xSpeed = b2.xSpeed * -1
b2.ySpeed = b2.ySpeed * -1
Return
End If
Next
Next
End Sub
i have updated the example in post #6 and also included a slowdown function + ball collision. Note that the collision is not 100% correct and may contain bugs this is why i didnot included it at the first place. i dont think you need to perform collision between balls in my opinion it would make the game harder if the balls dont collide and run over each other and only stops when they are not overlapping (This is already implemented in the code). but again this is my opinion and the code is included in post #6 (v2!)
EDIT: if you want a more accurate physics then for you animation i would use X2 that includes box2d and is also cross platform!!!