Games Library recommendation

Filippo

Expert
Licensed User
Longtime User
Hi,

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?

Video: Becherspiel.mp4

Ciao,
Filippo
 

ilan

Expert
Licensed User
Longtime User
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.

are u using canvas? Or rotating views?
 

Filippo

Expert
Licensed User
Longtime User
Hi @ilan ,

I use in principle your modified code for the animation:

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
 
Last edited:

ilan

Expert
Licensed User
Longtime User
it doesnot look like you need to use this approach which is using unnecessary cpu power.
you can just draw your bitmaps with different angle.

can you upload the graphics?
 

Filippo

Expert
Licensed User
Longtime User
it doesnot look like you need to use this approach which is using unnecessary cpu power.
you can just draw your bitmaps with different angle.
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.

can you upload the graphics?
what do you mean by graphics, the ball?


Video: Becherspiel_1.mp4
 

Attachments

  • kugelbecher_closed_240x240.png
    kugelbecher_closed_240x240.png
    64.7 KB · Views: 160
  • tablett_quadrat_480x220.png
    tablett_quadrat_480x220.png
    193.2 KB · Views: 162
Last edited:

Filippo

Expert
Licensed User
Longtime User
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.
 

ilan

Expert
Licensed User
Longtime User
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
 

ilan

Expert
Licensed User
Longtime User
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!!!

 
Top