Page 54 of 91
Re: "Questions that don't deserve their own thread" thread
Posted: Tue Mar 08, 2016 11:36 pm
by PrussianBlue
Alright, thank you very much for the help. I tried using ... inplace of arg but unpack threw an error. I realize now that it's because ... is a tuple instead of a table - in other words, it is already unpacked.
Re: "Questions that don't deserve their own thread" thread
Posted: Wed Mar 09, 2016 2:29 pm
by Skeiks
How much overhead does sending externs to a shader have? I'm working on a distortion effect for my game and I was sending a texture map to my shader almost every frame to do the effect. I didn't experience any slowdown, but I don't know if that's a bad practice or not.
Re: "Questions that don't deserve their own thread" thread
Posted: Fri Mar 11, 2016 8:42 am
by Snowbadger
Edit: Nevermind on that one. I finally figured out a fix.
Another question, though: If I were to compare arrays of strings, would there be a more efficient way than concatenating both arrays and comparing those resulting strings?
For example, if I had something like this to populate an empty array with user input in order to compare it with an existing array.
Code: Select all
array = { "apple", "banana", "pear" }
userArray = {}
-- extra code here to insert user input into userArray
string1 = table.concat(array, " ")
string2 = table.concat(userArray, " ")
if string1 == string2 then
-- do something
Re: "Questions that don't deserve their own thread" thread
Posted: Fri Mar 11, 2016 8:51 pm
by eliasfrost
Hi! I'm currently getting into programming games again and I'm trying to make a breakout clone. I'm having trouble with calculating the reflecting angle when the ball bounces on a surface.
What I'm currently doing is:
Code: Select all
ball.rads = ball.angle * math.pi / 180
ball.x = ball.x + math.cos(ball.rads)*(ball.speed*dt)
ball.y = ball.y + math.sin(ball.rads)*(ball.speed*dt)
if checkCollision(ball, v) then
ball.angle = 180 - ball.angle
end
It works but only for vertical surfaces. can someone explain or point me towards the info I need to get this to work? I've searched on google but the answers I've gotten seems like overkill. calculating velocity components with the normal of a surface or something, I'm not a physics graduate so I have no idea what they are talking about and finding comprehensible resources is hard.
Or maybe there's an even simpler way of doing things and I'm just on the wrong track? If someone feel like they can help me a bit please do.
Re: "Questions that don't deserve their own thread" thread
Posted: Sat Mar 12, 2016 2:56 am
by Skeiks
Snowbadger wrote:Edit: Nevermind on that one. I finally figured out a fix.
Another question, though: If I were to compare arrays of strings, would there be a more efficient way than concatenating both arrays and comparing those resulting strings?
For example, if I had something like this to populate an empty array with user input in order to compare it with an existing array.
Code: Select all
array = { "apple", "banana", "pear" }
userArray = {}
-- extra code here to insert user input into userArray
string1 = table.concat(array, " ")
string2 = table.concat(userArray, " ")
if string1 == string2 then
-- do something
Maybe concatenating the arrays wouldn't work 100% since tables could be in different orders. I dunno if concat handles sorting. If the strings are always going to be the same though I think that's actually a pretty efficient way of handling it.
It really depends on what you're comparing the tables for though. In some instances you may just have to do a 1 to 1 n^2 compare. In other instances, if you know the keys of a table, and the keys are irrelevant, set the keys to equal the string value and you could just look for keys. That way you could do N level search. Let's say you have a table array = {banana = "banana", apple = "apple", pear = "pear"}. You could do:
Code: Select all
match = true
array = {banana = "banana", apple = "apple", pear = "pear"}
userArray = {}
foreach key, value in userArray do
if array[key] then
continue;
end
match = false;
break;
end
This won't work if you need the keys to have information about the data they contain, but it is a pretty fast way to handle comparing tables I think. Maybe someone else could give a more complete answer.
Re: "Questions that don't deserve their own thread" thread
Posted: Mon Mar 14, 2016 12:38 am
by Taehl
eliasfrost wrote:Hi! I'm currently getting into programming games again and I'm trying to make a breakout clone. I'm having trouble with calculating the reflecting angle when the ball bounces on a surface.
...
I've searched on google but the answers I've gotten seems like overkill. calculating velocity components with the normal of a surface or something, I'm not a physics graduate so I have no idea what they are talking about and finding comprehensible resources is hard.
Or maybe there's an even simpler way of doing things and I'm just on the wrong track? If someone feel like they can help me a bit please do.
As long as you don't have angled surfaces or anything fancy like that, there's a simple age-old trick you can use (heck, the original Breakout probably even did this). Whenever your ball hits something, check if it hit vertically or horizontally, and simply multiply your y-velocity or x-velocity (respectively) by -1.
So it your ball is moving right and touches a wall on the right, all it needs to do is travel left at the same speed now. Hence the *-1 of your x-velocity.
Re: "Questions that don't deserve their own thread" thread
Posted: Mon Mar 14, 2016 5:01 pm
by childonline
Hi!
How am I supposed to canvas:clear() since 0.10.1 ? Is there a generally fast good-practice I don't know about?
Thanks!
Re: "Questions that don't deserve their own thread" thread
Posted: Mon Mar 14, 2016 5:37 pm
by Skeiks
childonline wrote:Hi!
How am I supposed to canvas:clear() since 0.10.1 ? Is there a generally fast good-practice I don't know about?
Thanks!
Set the canvas, then use love.graphics:clear()
Code: Select all
love.graphics.setCanvas(canvas);
love.graphics.clear();
love.graphics.setCanvas()
Re: "Questions that don't deserve their own thread" thread
Posted: Mon Mar 14, 2016 5:44 pm
by childonline
Skeiks wrote:
Set the canvas, then use love.graphics:clear()
Code: Select all
love.graphics.setCanvas(canvas);
love.graphics.clear();
love.graphics.setCanvas()
Thanks!
Re: "Questions that don't deserve their own thread" thread
Posted: Mon Mar 14, 2016 7:47 pm
by rmcode
I can't figure out how to extend
to also match strings with whitespace.
E.g.:
Code: Select all
FooBar = lalalalala -- works
Foo Bar = lalalalala -- doesn't work
I know you can wrap repeated captures in another capture in some languages, but this doesn't seem to work in lua:
Any ideas?