Page 1 of 1

problem with to sprite .

Posted: Thu Feb 16, 2017 1:41 pm
by Bernard51
hello
I try to create a Break out , my problem When I move my pad with the mouse , my pad Comes out of the screen

How to prevent my pad To exit the screen ?

Thank you


https://www.dropbox.com/s/93o00rk8disai ... t.zip?dl=0



Bernard

Re: problem with to sprite .

Posted: Thu Feb 16, 2017 2:07 pm
by evgiz
Hey!

Please upload a .love file so it is easier for everyone to test it.

Breakout.love
(11.81 KiB) Downloaded 162 times

Also some code examples are very helpful. To prevent the paddle from going outside the screen, you can add a simple check.
I didn't look at your code, but something like this would work:

Code: Select all

gameWidth = love.graphics.getWidth()
paddleWidth = 50

if paddle.x>gameWidth-paddleWidth then
	paddle.x = gameWidth-paddleWidth
end
Tweak paddle width accordingly. Good luck!

Re: problem with to sprite .

Posted: Thu Feb 16, 2017 2:16 pm
by Bernard51
Thank you evgiz

Do you add to which part of the code?

Re: problem with to sprite .

Posted: Thu Feb 16, 2017 2:43 pm
by evgiz
I can see in love.update you set the position of the paddle. Right below it, simply add the check if its out of the screen.
Hopefully you understand what the code does, otherwise you wont learn anything :P

love.update is called every frame, and is where game logic should take place most of the time. I'd recommend you take a look on the love wiki for more information!

Re: problem with to sprite .

Posted: Thu Feb 16, 2017 2:52 pm
by Bernard51
Hi

Thank you but it does not work the paddle comes out of the screen

Re: problem with to sprite .

Posted: Thu Feb 16, 2017 4:20 pm
by Nikki
Your update function needs some logic to not let that paddle come out the screen.

Code: Select all

function love.update(dt)
  -- On deplace la raquette avec la souris
   raquette.x = love.mouse.getX()
   if raquette.x > (largeur - imageRaquette:getWidth())  then
      raquette.x = largeur - imageRaquette:getWidth()
   end
   if (raquette.x < 0) then
      raquette.x = 0
   end
end

Re: problem with to sprite .

Posted: Thu Feb 16, 2017 4:47 pm
by Bernard51
thank you