Page 59 of 91
Re: "Questions that don't deserve their own thread" thread
Posted: Tue Mar 29, 2016 2:21 am
by CornSyrup
I'm sorry for asking the same question that others have asked but I don't know how to do collision detection? I'm making a tile game and I don't want the play to walk over things like trees, I know I'm supposed to use this
function CheckCollision(x1,y1,w1,h1, x2,y2,w2,h2)
return x1 < x2+w2 and
x2 < x1+w1 and
y1 < y2+h2 and
y2 < y1+h1
end
But I don't know where to put this or what to do with it honestly. I think it's obvious that I'm new to love2d and lua.
Re: "Questions that don't deserve their own thread" thread
Posted: Tue Mar 29, 2016 7:07 am
by bobismijnnaam
CornSyrup wrote:I'm sorry for asking the same question that others have asked but I don't know how to do collision detection? I'm making a tile game and I don't want the play to walk over things like trees, I know I'm supposed to use this
function CheckCollision(x1,y1,w1,h1, x2,y2,w2,h2)
return x1 < x2+w2 and
x2 < x1+w1 and
y1 < y2+h2 and
y2 < y1+h1
end
But I don't know where to put this or what to do with it honestly. I think it's obvious that I'm new to love2d and lua.
Just worked on that this weekend, and found the easiest way:
1. Have two boxes
2. Grow the first box with half the height of the second, and half the width of the second, as if it's origin is in its center. That is, it expands from it's center.
3. Shrink the second till it's a point (just take it's center)
4. Check if the point from 3 is within the box from 2
And viola! Collision detection at its simplest. Or you can just use the function you already had but this is more elegant imo :p
Basically you give that function two boxes (x y width height, two times) and then check for collision between your player and all the collidable tiles. An appropriate place to call it would be in the update function, after your player has moved. The function itself can be anywhere in global scope.
Re: "Questions that don't deserve their own thread" thread
Posted: Wed Mar 30, 2016 7:40 am
by Sfe
Hi, I'm dealing with a... weird problem right now.
For some reason, the love.mousepressed() function just does not want to work. It's not even that I'm doing anything complicated with it, I'm just trying to run the example function in the documentation. That is, this:
Code: Select all
function love.load()
printx = 0
printy = 0
end
function love.draw(dt)
love.graphics.print("Wow!",printx,printy)
end
function love.mousepressed(x,y,button,istouch)
if button == 1 then
printx = x
printy = y
end
end
(Whether I put the "istouch" there or not doesn't seem to make a difference).
But for some reason, clicking on the screen doesn't move the text around like it should! This isn't just a problem only with this code, as I'm having the same issue with the function in my actual code, but this is where it's clearest. Am I doing something wrong? Or did things get updated? Thanks for all the trouble.
Re: "Questions that don't deserve their own thread" thread
Posted: Wed Mar 30, 2016 8:45 am
by MadByte
Sfe wrote:...
Works as expected for me.
Double check that you don't use an older version of LÖVE accidentally.
Try using "l" instead of 1 or use love.getVersion() and print it.
Re: "Questions that don't deserve their own thread" thread
Posted: Wed Mar 30, 2016 9:06 am
by anastasiaorosegirl
MadByte wrote:Sfe wrote:...
Works as expected for me.
Double check that you don't use an older version of LÖVE accidentally.
Try using "l" instead of 1 or use love.getVersion() and print it.
I tried the code out and it doesn't seem to work as intended. I'm using OSX with LÖVE 0.10.1, so maybe that's it?
Re: "Questions that don't deserve their own thread" thread
Posted: Wed Mar 30, 2016 9:19 am
by bobismijnnaam
MadByte wrote:Sfe wrote:...
Works as expected for me.
Double check that you don't use an older version of LÖVE accidentally.
Try using "l" instead of 1 or use love.getVersion() and print it.
Same here. Maybe you're editing/executing the wrong file?
Re: "Questions that don't deserve their own thread" thread
Posted: Wed Mar 30, 2016 9:49 am
by anastasiaorosegirl
bobismijnnaam wrote:
...
Well, I am running it via the terminal using "open -n -a love main.lua" and using Atom as my editor. I'll try using something that let's me run the code in Atom and see if that changes anything.
Repeating video?
Posted: Wed Mar 30, 2016 10:14 am
by Ptruptrucea
I inserted a video in my project and I made it run under the main menu, everything works fine. I can't however for the life of me find a way to make the video repeat. Is there some method to the play function that loops the video?
I searched the wiki up and down and found nothing. If there isn't a way to loop it I guess I'll just have to make an extra long video and hope that the players don't waste too much time on the main menu
.
Re: "Questions that don't deserve their own thread" thread
Posted: Wed Mar 30, 2016 10:42 am
by MadByte
Ptruptrucea wrote:Is there some method to the play function that loops the video?
Can't you just do something like
Code: Select all
if not video:isPlaying() then
if video:tell() > 0 then video:rewind() end
video:play()
end
I never used the video functionality, so this is just an untested idea. Also I don't know if you need to rewind the video after it ends or if this happens automatically so I added the extra loop to make sure it does.
Re: "Questions that don't deserve their own thread" thread
Posted: Wed Mar 30, 2016 11:20 am
by Ptruptrucea
Thanks, MadByte, worked like a charm. I'm not only new to Love2d, but to programming as well, so solutions like yours don't come to me naturally
.