As the subject says, I have an object that I want to appear on the other side of the screen and I have done this before but I need to have my memory refreshed.
And if I remember correctly it's something like this: then object have a lesser value (or greater) than 0 (or 800) it will appear on the other side.
So if you please could nudge me on the right track I would be grateful.
Make an object appear on the other side of the screen
Make an object appear on the other side of the screen
Have a good day!
Re: Make an object appear on the other side of the screen
If I understand correctly you want that an object, that exits the screen on the right, reenters on the left? The you are right:
If you use the LÖVE default screen Width, then it is 800.
Code: Select all
if x > screenWidth then
x = x - screenWidth
end
if x < 0 then
x = x + screenWidth
end
Check out my blog on gamedev
Re: Make an object appear on the other side of the screen
Just to be sure: do I create a separate function for it or put it in love.draw?micha wrote:If I understand correctly you want that an object, that exits the screen on the right, reenters on the left? The you are right:If you use the LÖVE default screen Width, then it is 800.Code: Select all
if x > screenWidth then x = x - screenWidth end if x < 0 then x = x + screenWidth end
Have a good day!
Re: Make an object appear on the other side of the screen
Alternatively, you could use the modulo (https://en.wikipedia.org/wiki/Modulo_operation) operator.
Code: Select all
x = x % love.graphics.getWidth()
Re: Make an object appear on the other side of the screen
Solved it!micha wrote:If I understand correctly you want that an object, that exits the screen on the right, reenters on the left? The you are right:If you use the LÖVE default screen Width, then it is 800.Code: Select all
if x > screenWidth then x = x - screenWidth end if x < 0 then x = x + screenWidth end
The only mistake I did was using 'x' on local and give it a value of 800, which screw up some of the coding because I already have something that describes the x position.
Thanks for the help!
Have a good day!
Who is online
Users browsing this forum: Bing [Bot] and 3 guests