How can I clip with love.graphics.draw()

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
User avatar
vitaminx
Citizen
Posts: 95
Joined: Fri Oct 19, 2012 7:16 am
Location: international
Contact:

How can I clip with love.graphics.draw()

Post by vitaminx »

Hello all,

I'm quite new to löve, so please permit me this n00b question :crazy:

I'm trying to draw a loaded image on the screen with love.graphics.draw(), but only a rectangular part of it.
However, draw() doesn't do clipping.

What would be the right way to do that?

Thanks! vitaminx
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: How can I clip with love.graphics.draw()

Post by Robin »

Welcome!

You can do that with love.graphics.setScissor:

Code: Select all

love.graphics.setScissor(10, 10, 100, 100)
love.graphics.draw(image, 10, 10)
love.graphics.setScissor() -- disable the clipping
Help us help you: attach a .love.
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: How can I clip with love.graphics.draw()

Post by slime »

You can also use Quads.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: How can I clip with love.graphics.draw()

Post by T-Bone »

It sounds more like a job for Quads and love.graphics.drawq than a job for love.graphics.setScissor. But they'll both work.

Quads can be added to Spritebatches and Canvases as well if you want to use buffers.
User avatar
vitaminx
Citizen
Posts: 95
Joined: Fri Oct 19, 2012 7:16 am
Location: international
Contact:

Re: How can I clip with love.graphics.draw()

Post by vitaminx »

thanks a lot, I'm now using quads which are exactly what I needed.
girng
Prole
Posts: 40
Joined: Fri Sep 07, 2018 5:42 am

Re: How can I clip with love.graphics.draw()

Post by girng »

Robin wrote: Fri Oct 19, 2012 7:59 am Welcome!

You can do that with love.graphics.setScissor:

Code: Select all

love.graphics.setScissor(10, 10, 100, 100)
love.graphics.draw(image, 10, 10)
love.graphics.setScissor() -- disable the clipping
omg. ty sir was searching all over for this.

this works perfectly for health globes!

man, i'm really starting to like love2d
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: How can I clip with love.graphics.draw()

Post by zorg »

the scissor thing works in screenspace though, no transformations will affect it, so keep this in mind when you get to rotating/scaling stuff, since then, scissors won't exactly work.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 75 guests