Coding Fun Java Android Game Development in Java – Part 6: Collision Detection

Android Game Development in Java – Part 6: Collision Detection

Hey everyone, here is episode 6 of our walk through. Hope you enjoy!

Tags: , , , , , , , ,

27 thoughts on “Android Game Development in Java – Part 6: Collision Detection”

  1. Squille says:

    but if I set several objects on the stage, will I have to do an if for each combination possible? it would be almost impossible :/

  2. gapsongg says:


  3. can you give us the code?

  4. It's a big no-no, and is getting worse and worse with every episode so far. I really appreciate your efforts, mate, but no cheese for advocating awful coding practices.

  5. In the render function, I changed the rectangle for the tree to this
    sr.rect(newTree.getPosition().x + newTree.getSize().x /4, newTree.getPosition().y, newTree.getSize().x /2, newTree.getSize().y /4);

    Then in in the update function
    bounds.set(position.x + getSize().x /4, position.y, size.x /2, size.y / 4);

    This makes the collision bounds of the tree to be just the base of the tree which makes it a bit more realistic since you would never collide with the top of the tree unless the tree was laying down.

    The collision rectangle on the sprite could probably use a bit of tweaking as well to perhaps about 90% of the size of x.

  6. Rahul P says:

    rather than using a string movement, using booleans work much better

  7. Linfeng Li says:

    awesome, you help so much!

  8. A Jones says:

    in GL20 – sr.begin(ShapeType.rectangle) is sr.begin(ShapeType.Line );

  9. hey thanks for the tutorial it's awesome
    but just when we press multiple keys it has glitches.

  10. DarkN3ss says:

    Is it possible for you to upload the source after each video? 🙂 Thanks

  11. awesome video thx for making!

  12. KAT00N says:

    Awesome. You helped so much!

  13. JuanaJuanero says:

    Hi I tried running this to my Android phone but the player doesn't appear just white screen. tutorial 4 it was working fine up until tutorial 5 when we use a different image "Sprite Image".

  14. I found a way to avoid the glitchy collision, but sadly it sacrifices allowing the player to move diagonally and creating a custom method for the collision.
    Does anyone fix it in a simpler better way?

  15. xd50Calxd says:

    I shall leave a comment saying……"AWESOME!"

  16. Harpreet06 says:

    With the collision detection, the left and up movements work as intended but the down and right don't. With the down movement, when it collides with the rectangle is goes down diagonally to the left. With the right movement it goes up diagonally to the right.

  17. Harpreet06 says:

    My tree showed up fine until the shaperenderer bit. Now the tree doesn't show up. The red rectangle is still there but there's nothing inside.

  18. trial trll says:

    This is great!! Thank you very much and keep up the good work. I was able to follow and complete the whole thing, albeit slower than you, lol. I was just struggling to accept the bugs you mentioned at the end. I will try and figure out a way to correct it as a way to practice.

  19. Jean-Luc says:

    I wasn't able to do ShapeType.Rectangle, the only options are Fill, Line and Point. In this case Fill will fill in the rectangle, Line will fill the outline of the rectangle, and I haven't used Point so not sure about that.

  20. Tedsta101 says:

    Why is it telling me that my tree.png has to be to the power of 2? Howcome you were able to use an image that was 726×798, but my computer is giving me errors? 

  21. Jason Carag says:

    Great Job! Love the tutorials, been a great help for a noob like me!

  22. MishkaBrains says:

    awesome! You've helped so much!

  23. Flash says:

    thank you for everything! Continues! I'll support from France, Paris! : D

Leave a Reply

Your email address will not be published. Required fields are marked *