Difference between revisions of "Pixel:setTextureMatrix"

From GiderosMobile
(added example)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
+
'''Available since:''' in development<br/>
'''<translate>Available since</translate>:''' in development<br/>
+
'''Class:''' [[Special:MyLanguage/Pixel|Pixel]]<br/>
'''<translate>Class</translate>:''' [[Special:MyLanguage/Pixel|Pixel]]<br/>
+
 
=== <translate>Description</translate> ===
+
=== Description ===
<translate>Sets the matrix of the Pixel's texture</translate>
+
Sets the matrix of the Pixel's texture.
 
<source lang="lua">
 
<source lang="lua">
Pixel:setTextureMatrix(matrix)
+
Pixel:setTextureMatrix(matrix)
 +
</source>
 +
 
 +
=== Parameters ===
 +
'''matrix''': (Matrix) the matrix<br/>
 +
 
 +
=== Example ===
 +
<source lang="lua">
 +
-- a pixel holding a repeatable power of 2 texture
 +
local tex = Texture.new("gfx/myimg.jpg", false, {wrap = TextureBase.REPEAT})
 +
local img = Pixel.new(tex, tex:getWidth(), tex:getHeight())
 +
stage:addChild(img)
 +
-- the matrix
 +
local m = Matrix.new()
 +
-- some vars
 +
local flow = 0
 +
local flowspeed = 0.09
 +
 
 +
function onEnterFrame(e)
 +
flow += flowspeed
 +
m:setRotationZ(math.sin(flow)) -- rotate matrix on Z axis
 +
img:setTextureMatrix(m) -- apply modified matrix
 +
end
 +
 
 +
stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
 
</source>
 
</source>
=== <translate>Parameters</translate> ===
 
'''matrix''': (Matrix) <translate>The matrix.</translate> <br/>
 
  
 
{{Pixel}}
 
{{Pixel}}

Revision as of 21:26, 12 November 2020

Available since: in development
Class: Pixel

Description

Sets the matrix of the Pixel's texture.

Pixel:setTextureMatrix(matrix)

Parameters

matrix: (Matrix) the matrix

Example

-- a pixel holding a repeatable power of 2 texture
local tex = Texture.new("gfx/myimg.jpg", false, {wrap = TextureBase.REPEAT})
local img = Pixel.new(tex, tex:getWidth(), tex:getHeight())
stage:addChild(img)
-- the matrix
local m = Matrix.new()
-- some vars
local flow = 0
local flowspeed = 0.09

function onEnterFrame(e)
	flow += flowspeed
	m:setRotationZ(math.sin(flow)) -- rotate matrix on Z axis
	img:setTextureMatrix(m) -- apply modified matrix
end

stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)