SFML community forums

Help => Graphics => Topic started by: enderboy768 on May 14, 2017, 02:00:18 pm

Title: Simple Map Borders
Post by: enderboy768 on May 14, 2017, 02:00:18 pm
How do I create like an invisible wall at each side of my window so any moving object can not pass through it? I tried setting the speed to 0 or multiplying it by -1 if the object reach the side, but if I press the arrow keys several times it would still go through it. Sorry if this sounds like a noob question. Thank you in advance!  ;D
Title: Re: Simple Map Borders
Post by: fallahn on May 14, 2017, 02:59:07 pm
Have a look at this post which explains some basic collision testing. There's some sample code at the bottom:

http://trederia.blogspot.co.uk/2016/02/2d-physics-101-pong.html
Title: Re: Simple Map Borders
Post by: Carlos Augusto Br Cpp on June 01, 2017, 05:41:25 pm
You can make an if statement to check if the actual position of the object that you want to collide with walls, plus its own size, are greater or equal to the window side that you want...

I hope that it helps...

much love...