"Questions that don't deserve their own thread" thread

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Locked
CornSyrup
Prole
Posts: 1
Joined: Tue Mar 29, 2016 2:15 am

Re: "Questions that don't deserve their own thread" thread

Post 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.
User avatar
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

Post 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.
taart
lc = love.timer -- love.chrono :-)
Sfe
Prole
Posts: 2
Joined: Wed Mar 30, 2016 7:34 am

Re: "Questions that don't deserve their own thread" thread

Post 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.
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

Re: "Questions that don't deserve their own thread" thread

Post 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.
anastasiaorosegirl
Prole
Posts: 17
Joined: Sat Mar 26, 2016 7:18 pm

Re: "Questions that don't deserve their own thread" thread

Post 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?
User avatar
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

Post 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?
taart
lc = love.timer -- love.chrono :-)
anastasiaorosegirl
Prole
Posts: 17
Joined: Sat Mar 26, 2016 7:18 pm

Re: "Questions that don't deserve their own thread" thread

Post 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.
Ptruptrucea
Prole
Posts: 7
Joined: Wed Mar 30, 2016 10:10 am

Repeating video?

Post 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 :P .
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

Re: "Questions that don't deserve their own thread" thread

Post 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.
Ptruptrucea
Prole
Posts: 7
Joined: Wed Mar 30, 2016 10:10 am

Re: "Questions that don't deserve their own thread" thread

Post 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 :) .
Locked

Who is online

Users browsing this forum: Google [Bot], Yolwoocle and 212 guests