Difference between revisions of "Pixel:setTexturePosition"

From GiderosMobile
(added example)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
+
'''Available since:''' Gideros 2011.6<br/>
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
+
'''Class:''' [[Special:MyLanguage/Pixel|Pixel]]<br/>
'''<translate>Class</translate>:''' [[Special:MyLanguage/Pixel|Pixel]]<br/>
+
 
=== <translate>Description</translate> ===
+
=== Description ===
<translate>Sets the texture's position</translate>
+
Sets the texture's position.
 
<source lang="lua">
 
<source lang="lua">
Pixel:setTexturePosition(x,y)
+
Pixel:setTexturePosition(x,y)
 +
</source>
 +
 
 +
=== Parameters ===
 +
'''x''': (number) x-coordinate of texture <br/>
 +
'''y''': (any) y-coordinate of texture <br/>
 +
 
 +
=== Example ===
 +
<source lang="lua">
 +
-- a pixel holding a repeatable power of 2 texture
 +
local tex = Texture.new("gfx/image.jpg", true, {wrap = TextureBase.REPEAT})
 +
local img = Pixel.new(tex, tex:getWidth(), tex:getHeight())
 +
stage:addChild(img)
 +
-- some vars
 +
local flow = 0
 +
local flowspeed = 1
 +
 
 +
function onEnterFrame(e)
 +
flow += flowspeed
 +
img:setTexturePosition(0, flow) -- move the texture pixel on y axis
 +
end
 +
 
 +
stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
 
</source>
 
</source>
=== <translate>Parameters</translate> ===
 
'''x''': (number) <translate>x-coordinate of texture</translate> <br/>
 
'''y''': (any) <translate>y-coordinate of texture</translate> <br/>
 
  
 
{{Pixel}}
 
{{Pixel}}

Revision as of 20:36, 12 November 2020

Available since: Gideros 2011.6
Class: Pixel

Description

Sets the texture's position.

Pixel:setTexturePosition(x,y)

Parameters

x: (number) x-coordinate of texture
y: (any) y-coordinate of texture

Example

-- a pixel holding a repeatable power of 2 texture
local tex = Texture.new("gfx/image.jpg", true, {wrap = TextureBase.REPEAT})
local img = Pixel.new(tex, tex:getWidth(), tex:getHeight())
stage:addChild(img)
-- some vars
local flow = 0
local flowspeed = 1

function onEnterFrame(e)
	flow += flowspeed
	img:setTexturePosition(0, flow) -- move the texture pixel on y axis
end

stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)