"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.
-
- Prole
- Posts: 2
- Joined: Tue Mar 08, 2016 4:03 pm
Re: "Questions that don't deserve their own thread" thread
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
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.
-
- Prole
- Posts: 9
- Joined: Thu Jun 25, 2015 11:33 pm
Re: "Questions that don't deserve their own thread" thread
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.
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
Last edited by Snowbadger on Fri Mar 11, 2016 11:46 pm, edited 1 time in total.
-
- Prole
- Posts: 2
- Joined: Sun Nov 17, 2013 7:42 pm
Re: "Questions that don't deserve their own thread" thread
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:
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.
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
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
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
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: "Questions that don't deserve their own thread" thread
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.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.
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.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
- childonline
- Prole
- Posts: 15
- Joined: Thu Dec 30, 2010 11:06 am
Re: "Questions that don't deserve their own thread" thread
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!
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
Set the canvas, then use love.graphics:clear()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!
Code: Select all
love.graphics.setCanvas(canvas);
love.graphics.clear();
love.graphics.setCanvas()
- childonline
- Prole
- Posts: 15
- Joined: Thu Dec 30, 2010 11:06 am
Re: "Questions that don't deserve their own thread" thread
Thanks!Skeiks wrote: 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
I can't figure out how to extend to also match strings with whitespace.
E.g.:
I know you can wrap repeated captures in another capture in some languages, but this doesn't seem to work in lua:
Any ideas?
Code: Select all
^([%g]+)%s+=%s+(.+)
E.g.:
Code: Select all
FooBar = lalalalala -- works
Foo Bar = lalalalala -- doesn't work
Code: Select all
(([%g]+[%s]*)+)%s+=%s+(.+)
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 4 guests