Difference between revisions of "love.graphics.setStencil"

m (moved love.graphics.setMask to love.graphics.setStencil: Function was renamed.)
(s/mask/stencil)
Line 1: Line 1:
 
{{newin|[[0.8.0]]|080|type=function}}
 
{{newin|[[0.8.0]]|080|type=function}}
Defines or releases a mask for the drawing operations.
+
Defines or releases a stencil for the drawing operations.
  
The passed function draws to the mask instead of the screen, creating an image with transparent and opaque pixel. While active, it is used to test where pixel will be drawn or discarded.<br>
+
The passed function draws to the stencil instead of the screen, creating an image with transparent and opaque pixel. While active, it is used to test where pixel will be drawn or discarded.<br>
Calling the function without arguments releases the active mask.
+
Calling the function without arguments releases the active stencil.
 
== Function ==
 
== Function ==
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
love.graphics.setMask( maskFunction )
+
love.graphics.setStencil( stencilFunction )
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
{{param|function|maskFunction|Function that draws to the mask.}}
+
{{param|function|stencilFunction|Function that draws to the stencil.}}
 
=== Returns ===
 
=== Returns ===
 
Nothing.
 
Nothing.
Line 16: Line 16:
 
=== Synopsis ===
 
=== Synopsis ===
 
<source lang="lua">
 
<source lang="lua">
love.graphics.setMask( )
+
love.graphics.setStencil( )
 
</source>
 
</source>
 
=== Arguments ===
 
=== Arguments ===
Line 23: Line 23:
 
Nothing.
 
Nothing.
 
=== Notes ===
 
=== Notes ===
Releases the active mask.
+
Releases the active stencil.
 
== Examples ==
 
== Examples ==
 
=== Drawing circles masked by a rectangle ===
 
=== Drawing circles masked by a rectangle ===
 
<source lang="lua">
 
<source lang="lua">
myMaskFunction = function()
+
myStencilFunction = function()
 
   love.graphics.rectangle("fill", 225, 200, 350, 300)
 
   love.graphics.rectangle("fill", 225, 200, 350, 300)
 
end
 
end
  
myMask = love.graphics.newMask(myMaskFunction)
+
myStencil = love.graphics.newStencil(myStencilFunction)
  
love.graphics.setMask(myMask)
+
love.graphics.setStencil(myStencil)
  
 
love.graphics.setColor(255, 0, 0, 120)
 
love.graphics.setColor(255, 0, 0, 120)
Line 44: Line 44:
 
=== Drawing a circle with a hole ===
 
=== Drawing a circle with a hole ===
 
<source lang="lua">
 
<source lang="lua">
myMaskFunction = function()
+
myStencilFunction = function()
 
   love.graphics.circle("fill", 400, 300, 50)
 
   love.graphics.circle("fill", 400, 300, 50)
 
end
 
end
  
myMask = love.graphics.newMask(myMaskFunction)
+
myStencil = love.graphics.newStencil(myStencilFunction)
  
love.graphics.setInvertedMask(myMask)
+
love.graphics.setInvertedStencil(myStencil)
 
love.graphics.circle("fill", 400, 300, 150)
 
love.graphics.circle("fill", 400, 300, 150)
 
</source>
 
</source>
 
=== Drawing two masked triangles with different colors ===
 
=== Drawing two masked triangles with different colors ===
 
<source lang="lua">
 
<source lang="lua">
myMaskFunction = function()
+
myStencilFunction = function()
 
   love.graphics.circle("fill", 400, 300, 60, 25)
 
   love.graphics.circle("fill", 400, 300, 60, 25)
 
end
 
end
  
myMask = love.graphics.newMask(myMaskFunction)
+
myStencil = love.graphics.newStencil(myStencilFunction)
  
love.graphics.setMask(myMask)
+
love.graphics.setStencil(myStencil)
 
love.graphics.setColor(155, 0, 128)
 
love.graphics.setColor(155, 0, 128)
 
love.graphics.triangle("fill", 400, 200, 486, 350, 314, 350)
 
love.graphics.triangle("fill", 400, 200, 486, 350, 314, 350)
  
  
love.graphics.setInvertedMask(myMask)
+
love.graphics.setInvertedStencil(myStencil)
 
love.graphics.setColor(144, 214, 128)
 
love.graphics.setColor(144, 214, 128)
 
love.graphics.triangle("fill", 400, 200, 486, 350, 314, 350)
 
love.graphics.triangle("fill", 400, 200, 486, 350, 314, 350)
Line 72: Line 72:
 
== See Also ==
 
== See Also ==
 
* [[parent::love.graphics]]
 
* [[parent::love.graphics]]
* [[parent::love.graphics.newMask]]
+
* [[parent::love.graphics.newStencil]]
* [[parent::love.graphics.setInvertedMask]]
+
* [[parent::love.graphics.setInvertedStencil]]
 
[[Category:Functions]]
 
[[Category:Functions]]
{{#set:Description=Defines or releases a mask.}}
+
{{#set:Description=Defines or releases a stencil.}}
 
{{#set:Since=080}}
 
{{#set:Since=080}}
 
== Other Languages ==
 
== Other Languages ==
{{i18n|love.graphics.setMask}}
+
{{i18n|love.graphics.setStencil}}

Revision as of 19:18, 12 August 2011

Available since LÖVE 0.8.0
This function is not supported in earlier versions.

Defines or releases a stencil for the drawing operations.

The passed function draws to the stencil instead of the screen, creating an image with transparent and opaque pixel. While active, it is used to test where pixel will be drawn or discarded.
Calling the function without arguments releases the active stencil.

Function

Synopsis

love.graphics.setStencil( stencilFunction )

Arguments

function stencilFunction
Function that draws to the stencil.

Returns

Nothing.

Function

Synopsis

love.graphics.setStencil( )

Arguments

None.

Returns

Nothing.

Notes

Releases the active stencil.

Examples

Drawing circles masked by a rectangle

myStencilFunction = function()
   love.graphics.rectangle("fill", 225, 200, 350, 300)
end

myStencil = love.graphics.newStencil(myStencilFunction)

love.graphics.setStencil(myStencil)

love.graphics.setColor(255, 0, 0, 120)
love.graphics.circle("fill", 300, 300, 150, 50)
love.graphics.setColor(0, 255, 0, 120)
love.graphics.circle("fill", 500, 300, 150, 50)
love.graphics.setColor(0, 0, 255, 120)
love.graphics.circle("fill", 400, 400, 150, 50)

Drawing a circle with a hole

myStencilFunction = function()
   love.graphics.circle("fill", 400, 300, 50)
end

myStencil = love.graphics.newStencil(myStencilFunction)

love.graphics.setInvertedStencil(myStencil)
love.graphics.circle("fill", 400, 300, 150)

Drawing two masked triangles with different colors

myStencilFunction = function()
   love.graphics.circle("fill", 400, 300, 60, 25)
end

myStencil = love.graphics.newStencil(myStencilFunction)

love.graphics.setStencil(myStencil)
love.graphics.setColor(155, 0, 128)
love.graphics.triangle("fill", 400, 200, 486, 350, 314, 350)


love.graphics.setInvertedStencil(myStencil)
love.graphics.setColor(144, 214, 128)
love.graphics.triangle("fill", 400, 200, 486, 350, 314, 350)

See Also


Other Languages