[Libgdx] First game: Breakout clone -- ball randomly does not deflect off wall

Hi all,

New to Java, libgdx and programming in general. I have no experience in programming prior to this. No CS degree, so my knowledge of the theory behind computers and math is really poor. Spent 2 months on C and objective-c before hopping on to the libgdx and java bandwagon. After a week of trying, I finally completed(sort of) a breakout clone.

Problem: the ball goes crazy at random and sticks to the wall/paddle when it should deflect itself off. Here’s the link to my files: https://github.com/crazyhendrix/libGDX-BreakOut

I was hoping someone can go through my code and see if I could have done things a little better.

The ball can get stuck on wall when ball’s velocity is high enough. It gets inside wall and can’t get out if next frame’s length is not greater than previous’ frame length (delta varies by frame by frame). There are many solutions, the simplest could be to just move the ball back to it’s previous position when collision occurs.

Very clean code on github, well done!

I had same problem when I made my breakout clone. :wink:

JVallius: Thanks for the reply. I was afraid that I might have done something wrong. Thanks for the explanation. :slight_smile:

Edit: I did as you said and now the problem is gone. Thanks!