Sprite:set: Difference between revisions

From GiderosMobile
No edit summary
No edit summary
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
'''Available since:''' Gideros 2011.6<br/>
=== <translate>Description</translate> ===
'''Class:''' [[Sprite]]<br/>
<translate><br />
 
Sets the specified property of this sprite instance by its name. These names are supported:<br />
=== Description ===
<br />
Sets the values of a sprite instance by name.
<ul><br />
<syntaxhighlight lang="lua">
<li>[[Special:MyLanguage/"x"|"x"]]</li><br />
Sprite:set(param, value)
<li>[[Special:MyLanguage/"y"|"y"]]</li><br />
</syntaxhighlight>
<li>[[Special:MyLanguage/"z"|"z"]]</li><br />
 
<li>[[Special:MyLanguage/"rotation"|"rotation"]]</li><br />
The possible names for '''param''' are:
<li>[[Special:MyLanguage/"rotationX"|"rotationX"]]</li><br />
*''"x"''
<li>[[Special:MyLanguage/"rotationY"|"rotationY"]]</li><br />
*''"y"''
<li>[[Special:MyLanguage/"scaleX"|"scaleX"]]</li><br />
*''"z"''
<li>[[Special:MyLanguage/"scaleY"|"scaleY"]]</li><br />
*''"rotation"''
<li>[[Special:MyLanguage/"scaleZ"|"scaleZ"]]</li><br />
*''"rotationX"''
<li>[[Special:MyLanguage/"alpha"|"alpha"]]</li><br />
*''"rotationY"''
<li>[[Special:MyLanguage/"redMultiplier"|"redMultiplier"]]</li><br />
*''"scale"''
<li>[[Special:MyLanguage/"greenMultiplier"|"greenMultiplier"]]</li><br />
*''"scaleX"''
<li>[[Special:MyLanguage/"blueMultiplier"|"blueMultiplier"]]</li><br />
*''"scaleY"''
<li>[[Special:MyLanguage/"alphaMultiplier"|"alphaMultiplier"]]</li><br />
*''"scaleZ"''
<li>[[Special:MyLanguage/"anchorX"|"anchorX"]]</li><br />
*''"anchorX"''
<li>[[Special:MyLanguage/"anchorY"|"anchorY"]]</li><br />
*''"anchorY"''
<li>[[Special:MyLanguage/"anchorZ"|"anchorZ"]]</li><br />
*''"anchorZ"''
</ul><br />
*''"alpha"''
<br /></translate>
*''"redMultiplier"''
<source lang="lua">
*''"greenMultiplier"''
Sprite:set(param,value)
*''"blueMultiplier"''
</source>
*''"alphaMultiplier"''
=== <translate>Parameters</translate> ===
*''"skewX"''
'''param''': (string) <translate>The name of the parameter</translate> <br/>
*''"skewY"''
'''value''': (number) <translate>The new value of the specified parameter</translate> <br/>
 
=== <translate>Examples</translate> ===
=== Parameters ===
'''Example'''<br/>
'''param''': (string) the name of the parameter<br/>
<source lang="lua">-- the following two lines do the same thing
'''value''': (number) the new value of the specified parameter<br/>
 
=== Examples ===
<syntaxhighlight lang="lua">
-- the following two lines do the same thing
sprite:setX(10)
sprite:setX(10)
sprite:set(&quot;x&quot;, 10)
sprite:set("x", 10)
-- the following two lines do the same thing
-- the following two lines do the same thing
sprite:setY(10)
sprite:setY(10)
sprite:set(&quot;y&quot;, 10)
sprite:set("y", 10)


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


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


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


-- the following two lines do the same thing
-- the following two lines do the same thing
sprite:setScale(0.5)
sprite:setScale(0.5)
sprite:set(&quot;scale&quot;, 0.5)</source>
sprite:set("scale", 0.5)
</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}}

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