Sprite:set: Difference between revisions

From GiderosMobile
formatting
No edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
<languages />
'''Available since:''' Gideros 2011.6<br/>
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
'''Class:''' [[Sprite]]<br/>
'''<translate>Class</translate>:''' [[Special:MyLanguage/Sprite|Sprite]]<br/>


=== <translate>Description</translate> ===
=== Description ===
Sets the specified property of this sprite instance by its name. These names are supported:
Sets the values of a sprite instance by name.
<ul>
<syntaxhighlight lang="lua">
<li>''"x"''</li>
Sprite:set(param, value)
<li>''"y"''</li>
</syntaxhighlight>
<li>''"z"''</li>
<li>''"rotation"''</li>
<li>''"rotationX"''</li>
<li>''"rotationY"''</li>
<li>''"scaleX"''</li>
<li>''"scaleY"''</li>
<li>''"scaleZ"''</li>
<li>''"alpha"''</li>
<li>''"redMultiplier"''</li>
<li>''"greenMultiplier"''</li>
<li>''"blueMultiplier"''</li>
<li>''"alphaMultiplier"''</li>
<li>''"anchorX"''</li>
<li>''"anchorY"''</li>
<li>''"anchorZ"''</li>
</ul>
<source lang="lua">
Sprite:set(param,value)
</source>


=== <translate>Parameters</translate> ===
The possible names for '''param''' are:
'''param''': (string) <translate>The name of the parameter</translate> <br/>
*''"x"''
'''value''': (number) <translate>The new value of the specified parameter</translate> <br/>
*''"y"''
*''"z"''
*''"rotation"''
*''"rotationX"''
*''"rotationY"''
*''"scale"''
*''"scaleX"''
*''"scaleY"''
*''"scaleZ"''
*''"anchorX"''
*''"anchorY"''
*''"anchorZ"''
*''"alpha"''
*''"redMultiplier"''
*''"greenMultiplier"''
*''"blueMultiplier"''
*''"alphaMultiplier"''
*''"skewX"''
*''"skewY"''


=== <translate>Examples</translate> ===
=== Parameters ===
<source lang="lua">
'''param''': (string) the name of the parameter<br/>
'''value''': (number) the new value of the specified parameter<br/>
 
=== Examples ===
<syntaxhighlight lang="lua">
-- the following two lines do the same thing
-- the following two lines do the same thing
sprite:setX(10)
sprite:setX(10)
Line 58: Line 60:
sprite:setScale(0.5)
sprite:setScale(0.5)
sprite:set("scale", 0.5)
sprite:set("scale", 0.5)
</source>
</syntaxhighlight>
 
''' A camera that follows the player'''
<syntaxhighlight lang="lua">
-- GAME LOOP
function Level:onEnterFrame(e)
-- camera follow
posx, posy = self.player1.player:getPosition()
self.camanchorx, self.camanchory = self.camera:getAnchorPosition()
self.camera:set("anchorX", posx / self.camera:getScale())
self.camera:set("anchorY", posy / self.camera:getScale())
end
</syntaxhighlight>


{{Sprite}}
{{Sprite}}

Latest revision as of 21:46, 13 March 2026

Available since: Gideros 2011.6
Class: Sprite

Description

Sets the values of a sprite instance by name.

Sprite:set(param, value)

The possible names for param are:

  • "x"
  • "y"
  • "z"
  • "rotation"
  • "rotationX"
  • "rotationY"
  • "scale"
  • "scaleX"
  • "scaleY"
  • "scaleZ"
  • "anchorX"
  • "anchorY"
  • "anchorZ"
  • "alpha"
  • "redMultiplier"
  • "greenMultiplier"
  • "blueMultiplier"
  • "alphaMultiplier"
  • "skewX"
  • "skewY"

Parameters

param: (string) the name of the parameter
value: (number) the new value of the specified parameter

Examples

-- the following two lines do the same thing
sprite:setX(10)
sprite:set("x", 10)
		
-- the following two lines do the same thing
sprite:setY(10)
sprite:set("y", 10)

-- the following two lines do the same thing
sprite:setRotation(10)
sprite:set("rotation", 10)

-- the following two lines do the same thing
sprite:setScaleX(0.5)
sprite:set("scaleX", 0.5)

-- the following two lines do the same thing
sprite:setScaleY(0.5)
sprite:set("scaleY", 0.5)

-- the following two lines do the same thing
sprite:setScale(0.5)
sprite:set("scale", 0.5)

A camera that follows the player

-- GAME LOOP
function Level:onEnterFrame(e)
	-- camera follow
	posx, posy = self.player1.player:getPosition()
	self.camanchorx, self.camanchory = self.camera:getAnchorPosition()
	self.camera:set("anchorX", posx / self.camera:getScale())
	self.camera:set("anchorY", posy / self.camera:getScale())
end