How can I handle collisions with obstacles in LibGDX?
Is there any automatic way to stop the character's movement when it collides with a wall or I have to constantly poll for all the possible objects it might encounter and stop the movement accordingly? Polling this way seems pretty poor performance-wise, especially if the framework already does that for me and I make no use of it.
My game is a top view roguelike, more or less like "The Binding of Isaac".
EDIT some beginners like me might make good use of it. Since LibGDX has no built in collision detection without Box2D, for games where physic calculation is not needed you can build your system as follows: Create 3 lists (Static, Dynamic, Controlled) where you put all your (relatively inherited) objects in the scene.
Static objects (walls, obstacles, traps) are passive and perform no checks.
Dynamic objects (projectiles) perform checks on both Static (stop if you hit a wall, destroy self) and Controlled (deal damage)
Controlled (players, enemies) objects perform checks on self (player hit AI controlled enemy) and static objects
After a collision is reported notify the relative objects. Controlled objects can be Dynamic aswell but if you have a lot of projectiles flying around you can avoid self-checking Dynamics and improve the performance. This way you should reduce a lot of useless checks aswell as limit cross-checks (both player and projectile notifying eachother) and keep your game well organized. This is just an idea that i'm testing now, I can't guarantee it's the best :P
dst(Vector2 other)
function. Or, if you want to avoid creating new objects every time, just copy thedst()
function into your own method. \$\endgroup\$