QUAD flip horizontal and vertical

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.
Post Reply

add back the quad:flip method?

Poll ended at Sun Nov 03, 2024 5:08 am

yes
0
No votes
please
1
20%
nope
4
80%
 
Total votes: 5

Rigachupe
Party member
Posts: 100
Joined: Fri Jun 18, 2021 11:21 am

QUAD flip horizontal and vertical

Post by Rigachupe »

Hi to the devs of this API. I ask you to consider returning back the quad:flip(x,y) function. It seems the idea was right and usuable correctly but then in 0.9.0 version removed from API.

Can this be returned back? From the quick look at the source file of quad.cpp i see that only 2 variables are needed to be added and then the u/v coords of texture are recalculated without changing the two triangles or 4 points.

Maybe someone hated the solution and they recommended the -scaleX or -scaleY option in love.graphics.draw. Which i consider not bad but more ugly than using quad:flip(x,y). This way the drawing becomes less overcalculated by adding offsets when flipping by hand through -scale while having the origin point not in the center of the sprite.

PS:I recommend also adding the quad:clone method. It would help in some cases to have it at hand ready.
User avatar
dusoft
Party member
Posts: 655
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: QUAD flip horizontal and vertical

Post by dusoft »

You can add that function yourself, right, if you don't like simple negation? Lua allows for table overrides etc.
I mean, I don't know the reasons, nor had used that function. Maybe @slime will chip in.
User avatar
pgimeno
Party member
Posts: 3673
Joined: Sun Oct 18, 2015 2:58 pm

Re: QUAD flip horizontal and vertical

Post by pgimeno »

Not that easy, but doable.

Code: Select all

  debug.getregistry().Quad.flip = function (self, x, y)
    local vpx, vpy, vpw, vph = self:getViewport()
    local vpsx, vpsy = self:getTextureDimensions()
    if x then
      vpx = -vpx - vpw
      vpsx = -vpsx
    end
    if y then
      vpy = -vpy - vph
      vpsy = -vpsy
    end
    self:setViewport(vpx, vpy, vpw, vph, vpsx, vpsy)
  end
RNavega
Party member
Posts: 385
Joined: Sun Aug 16, 2020 1:28 pm

Re: QUAD flip horizontal and vertical

Post by RNavega »

Now that's some sorcery right there, patching an API class with a new function.
User avatar
pgimeno
Party member
Posts: 3673
Joined: Sun Oct 18, 2015 2:58 pm

Re: QUAD flip horizontal and vertical

Post by pgimeno »

Generally I'm strongly against adding new functions to existing classes or tables, as that hinders readability (it's what many people do when they write a math.round() function or other similar ones, thinking it's clever to extend the existing math library), but in this case it's more like reviving a function that was once there, and if someone needs to look it up, the docs are available.
Rigachupe
Party member
Posts: 100
Joined: Fri Jun 18, 2021 11:21 am

Re: QUAD flip horizontal and vertical

Post by Rigachupe »

pgimeno wrote: Fri Jul 26, 2024 2:26 pm Not that easy, but doable.

Code: Select all

  debug.getregistry().Quad.flip = function (self, x, y)
    local vpx, vpy, vpw, vph = self:getViewport()
    local vpsx, vpsy = self:getTextureDimensions()
    if x then
      vpx = -vpx - vpw
      vpsx = -vpsx
    end
    if y then
      vpy = -vpy - vph
      vpsy = -vpsy
    end
    self:setViewport(vpx, vpy, vpw, vph, vpsx, vpsy)
  end
Now that is something i can only wonder about. Nice! I like it as a solution. Thanks! It works.
User avatar
dusoft
Party member
Posts: 655
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: QUAD flip horizontal and vertical

Post by dusoft »

pgimeno wrote: Fri Jul 26, 2024 3:34 pm Generally I'm strongly against adding new functions to existing classes or tables, as that hinders readability (it's what many people do when they write a math.round() function or other similar ones, thinking it's clever to extend the existing math library), but in this case it's more like reviving a function that was once there, and if someone needs to look it up, the docs are available.
Sure, but if backward compatibility is required, this will work. I.e. you could create a polyfill using your technique to run older games, where functions have been phased out by newer LOVE versions.
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests