SFML community forums
Help => General => Topic started by: AStar on March 08, 2018, 08:38:52 am
-
The box collision provided by SFML doesn't work. My enemy sprite simply does not trigger the game over. It just goes through the player sprite.
My code: https://pastebin.com/G9BK4Chc (https://pastebin.com/G9BK4Chc)
-
It's more that your logic doesn't work. ;)
You set the rects once and then never change them. You need to update the rects when you change the positions of the sprites.
Additionally, you shouldn't have thst collision check inside your event loop.
-
How to update the rects? And where should I put the collision checks? (Thanks for the fast reply)
-
The same way you set the rects in the first place. ;)
I usually go with the following procedure: process events, update/physics/collision, draw stuff
So you'd have it between your event loop and the drawing.
This however means that you'll probably want to look into making things independent of your refresh rate.
-
Just a last request - Can you give me an example code of what do you mean by the above reply?