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 .
borr
Prole
Posts: 42 Joined: Wed Oct 16, 2019 7:39 pm
Post
by borr » Sun Oct 09, 2022 1:48 pm
i want to limit the text to a given area
the only method i found along with stencil
Code: Select all
local function myStencilFunction()
love.graphics.rectangle("fill", 100, s_height/2, 95, 30)
end
function love.load()
text_obj = love.graphics.newText( font, "This text is aligned center")
end
function love.draw()
love.graphics.stencil(myStencilFunction, "replace", 1)
love.graphics.setStencilTest("greater", 0)
love.graphics.draw( text_obj, 100, s_height/2 )
love.graphics.setStencilTest()
end
are there any more productive methods for this?
Attachments
stencil_text.jpg (1.98 KiB) Viewed 4404 times
borr
Prole
Posts: 42 Joined: Wed Oct 16, 2019 7:39 pm
Post
by borr » Sun Oct 09, 2022 3:32 pm
Code: Select all
love.graphics.printf("This text is aligned center", s_width/2, s_height/2, 200,"center")
thanks for your reply.
but that's not what I want. I want the text outside of its area to be cut off
am I doing something wrong with the printf?
Attachments
printf_text.jpg (3.88 KiB) Viewed 4386 times
slime
Solid Snayke
Posts: 3166 Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:
Post
by slime » Sun Oct 09, 2022 3:35 pm
If you want text to be clipped instead of wrapping,
love.graphics.setScissor or stencils (as you've already discovered) are two good tools for it.
borr
Prole
Posts: 42 Joined: Wed Oct 16, 2019 7:39 pm
Post
by borr » Sun Oct 09, 2022 3:43 pm
Thanks
borr
Prole
Posts: 42 Joined: Wed Oct 16, 2019 7:39 pm
Post
by borr » Sun Oct 09, 2022 4:01 pm
can i add parameters for StencilFunction?
keharriso
Party member
Posts: 109 Joined: Fri Nov 16, 2012 9:34 pm
Post
by keharriso » Sun Oct 09, 2022 5:54 pm
borr wrote: ↑ Sun Oct 09, 2022 4:01 pm
can i add parameters for StencilFunction?
Maybe try returning a stencil function from a generator?
Code: Select all
local function generateStencil(x, y, width, height)
return function ()
love.graphics.rectangle("fill", x, y, width, height)
end
end
function love.draw()
love.graphics.stencil(generateStencil(100, 100, 95, 30), "replace", 1)
...
end
LÖVE-Nuklear - a lightweight immediate mode GUI for LÖVE games
borr
Prole
Posts: 42 Joined: Wed Oct 16, 2019 7:39 pm
Post
by borr » Sun Oct 09, 2022 6:37 pm
it works. Thanks
borr
Prole
Posts: 42 Joined: Wed Oct 16, 2019 7:39 pm
Post
by borr » Sun Oct 09, 2022 7:43 pm
love.graphics.setScissor( s_width/2 - text_obj:getWidth()/2, s_height / 2 - text_obj:getHeight() / 2, 95, 30 )
love.graphics.clear(0, 0, 0, 0)
clear with alpha 0, does not work without canvas?
Users browsing this forum: Ahrefs [Bot] , Amazon [Bot] , Bing [Bot] , Google [Bot] and 9 guests