problem with to sprite .

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
Bernard51
Prole
Posts: 46
Joined: Fri Jan 20, 2017 5:51 pm

problem with to sprite .

Post 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
User avatar
evgiz
Citizen
Posts: 83
Joined: Mon Aug 29, 2016 11:05 pm
Contact:

Re: problem with to sprite .

Post by evgiz »

Hey!

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

Breakout.love
(11.81 KiB) Downloaded 144 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!
Computer science student and part time game dev! Currently working on Depths of Limbo! :cool:

Check out the game website DepthsOfLimbo.com! :ultrahappy:
And my personal website with all my projects evgiz.net! :megagrin:
Bernard51
Prole
Posts: 46
Joined: Fri Jan 20, 2017 5:51 pm

Re: problem with to sprite .

Post by Bernard51 »

Thank you evgiz

Do you add to which part of the code?
User avatar
evgiz
Citizen
Posts: 83
Joined: Mon Aug 29, 2016 11:05 pm
Contact:

Re: problem with to sprite .

Post 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!
Computer science student and part time game dev! Currently working on Depths of Limbo! :cool:

Check out the game website DepthsOfLimbo.com! :ultrahappy:
And my personal website with all my projects evgiz.net! :megagrin:
Bernard51
Prole
Posts: 46
Joined: Fri Jan 20, 2017 5:51 pm

Re: problem with to sprite .

Post by Bernard51 »

Hi

Thank you but it does not work the paddle comes out of the screen
User avatar
Nikki
Citizen
Posts: 83
Joined: Wed Jan 25, 2017 5:42 pm

Re: problem with to sprite .

Post 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
Bernard51
Prole
Posts: 46
Joined: Fri Jan 20, 2017 5:51 pm

Re: problem with to sprite .

Post by Bernard51 »

thank you
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 96 guests