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.
"Questions that don't deserve their own thread" thread
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- bobismijnnaam
- Prole
- Posts: 18
- Joined: Thu Mar 17, 2016 5:18 pm
- Location: Netherlands
- Contact:
Re: "Questions that don't deserve their own thread" thread
Just worked on that this weekend, and found the easiest way: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.
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.
lc = love.timer -- love.chrono :-)
Re: "Questions that don't deserve their own thread" thread
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:
(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.
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
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
Works as expected for me.Sfe wrote:...
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.
-
- Prole
- Posts: 17
- Joined: Sat Mar 26, 2016 7:18 pm
Re: "Questions that don't deserve their own thread" thread
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?MadByte wrote:Works as expected for me.Sfe wrote:...
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.
- bobismijnnaam
- Prole
- Posts: 18
- Joined: Thu Mar 17, 2016 5:18 pm
- Location: Netherlands
- Contact:
Re: "Questions that don't deserve their own thread" thread
Same here. Maybe you're editing/executing the wrong file?MadByte wrote:Works as expected for me.Sfe wrote:...
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.
lc = love.timer -- love.chrono :-)
-
- Prole
- Posts: 17
- Joined: Sat Mar 26, 2016 7:18 pm
Re: "Questions that don't deserve their own thread" thread
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.bobismijnnaam wrote: ...
-
- Prole
- Posts: 7
- Joined: Wed Mar 30, 2016 10:10 am
Repeating video?
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 .
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
Can't you just do something likePtruptrucea wrote:Is there some method to the play function that loops the video?
Code: Select all
if not video:isPlaying() then
if video:tell() > 0 then video:rewind() end
video:play()
end
-
- Prole
- Posts: 7
- Joined: Wed Mar 30, 2016 10:10 am
Re: "Questions that don't deserve their own thread" thread
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 .
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 4 guests