Pixel:setTextureMatrix: Difference between revisions

From GiderosMobile
No edit summary
No edit summary
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
'''Available since:''' in development<br/>
'''Available since:''' Gideros 2016.12<br/>
'''Class:''' [[Pixel]]<br/>
 
=== Description ===
=== Description ===
Sets the matrix of the Pixel's texture
Sets the matrix of the Pixel's texture.
<source lang="lua">
<syntaxhighlight lang="lua">
Pixel:setTextureMatrix(matrix)
Pixel:setTextureMatrix(matrix)
</source>
</syntaxhighlight>
 
=== Parameters ===
=== Parameters ===
'''matrix''': (Matrix) The matrix. <br/>
'''matrix''': (Matrix) the matrix<br/>
 
=== Example ===
<syntaxhighlight 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)
</syntaxhighlight>
 
{{Pixel}}

Latest revision as of 20:53, 7 November 2023

Available since: Gideros 2016.12
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)