Search found 1495 matches

by pgimeno
Sun Jan 27, 2019 12:35 pm
Forum: Support and Development
Topic: Class Best Practices
Replies: 16
Views: 1513

Re: Class Best Practices

In some cases, it may be faster to clear and reuse existing tables instead of creating new ones all the time. Not just in some cases. In my experiments, clearing all elements of the table in a loop beat recreating the object every time. I couldn't get recreation to be faster. EDIT: Importantly, the...
by pgimeno
Fri Jan 25, 2019 11:10 pm
Forum: Support and Development
Topic: Querying the type name of ffi-declared cdata
Replies: 4
Views: 509

Re: Querying the type name of ffi-declared cdata

Gah, rookie mistake! You're right of course, sorry. What confuses me is that these ctype objects, even though they are distinct objects, have no distinct identity when converted to a string. tostring(cdata) is `cdata<whatever>: 0x12345678`, so tostring(ctype) should be `ctype<whatever>: 0x87654321`,...
by pgimeno
Fri Jan 25, 2019 9:24 pm
Forum: Support and Development
Topic: Querying the type name of ffi-declared cdata
Replies: 4
Views: 509

Re: Querying the type name of ffi-declared cdata

Can someone explain this behavior: <snip> Since the first print outputs 'true', I expected the bottom four lines to print 'int', but only the last one does. ffi.typeof "[c]reates a ctype object for the given ct" (according to the manual). If it's a new object, it's not surprising that using it as a...
by pgimeno
Fri Jan 25, 2019 12:17 am
Forum: Support and Development
Topic: Can't get accurate trajectory predictions with Box2d
Replies: 2
Views: 703

Re: Can't get accurate trajectory predictions with Box2d

I haven't checked your units in detail, so there may be a bug there, but what I consider most likely is that you're hitting some internal Box2D clamping. I've made this experiment: local lph, lg = love.physics, love.graphics local metre = 10 local gravity = 40 local Vx, Vy = 40, -400 lph.setMeter(me...
by pgimeno
Wed Jan 23, 2019 1:18 am
Forum: Support and Development
Topic: [SOLVED] Drawing on canvas works wrong
Replies: 7
Views: 1203

Re: [SOLVED] Drawing on canvas works wrong

Anything drawn with this function will be tinted according to the currently selected color. Set it to pure white to preserve the object's original colors. Hm, that's only true when using the default shader, which is the one that tints it. When using a custom shader, it depends on whether the shader...
by pgimeno
Wed Jan 23, 2019 1:08 am
Forum: Support and Development
Topic: How to achieve this type of water effect through a shader?
Replies: 3
Views: 1081

Re: How to achieve this type of water effect through a shader?

Here's an implementation of the above idea: local lg, lt, le = love.graphics, love.timer, love.event local shader = lg.newShader[[ extern vec4 base; extern vec4 maxc; extern number t; vec4 effect(vec4 col, Image tex, vec2 imgpos, vec2 scrpos) { vec4 c = Texel(tex, imgpos); float i = (sin(t) + 1.) / ...
by pgimeno
Tue Jan 22, 2019 6:08 pm
Forum: Support and Development
Topic: Using a single return value of a fucntion
Replies: 6
Views: 934

Re: Using a single return value of a fucntion

Oh you can, with parentheses:

Code: Select all

two = ({foo()})[2]
But using that method implies creation and destruction of an object unnecessarily.
by pgimeno
Tue Jan 22, 2019 6:04 pm
Forum: Support and Development
Topic: Using a single return value of a fucntion
Replies: 6
Views: 934

Re: Using a single return value of a fucntion

Note that select() returns all values starting on the specified one, so in this case it would return 2, 3. If you don't want that, you can isolate the parameter by wrapping the select in parentheses: local function foo() return "a", "b", "c" end local table1 = { select(2, foo()) } local table2 = { (...
by pgimeno
Tue Jan 22, 2019 2:17 am
Forum: Support and Development
Topic: [SOLVED] Drawing on canvas works wrong
Replies: 7
Views: 1203

Re: Drawing on canvas works wrong

You need to draw the canvas to the screen with white colour, otherwise you're tinting it :)

The last clear() isn't necessary, by the way.