Difference between revisions of "Sprite:set"

From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(8 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>Class</translate>:''' [[Special:MyLanguage/Sprite|Sprite]]<br/>
+
'''Class:''' [[Sprite]]<br/>
=== <translate>Description</translate> ===
+
 
<translate><br />
+
=== Description ===
Sets the specified property of this sprite instance by its name. These names are supported:<br />
+
Sets the values of a sprite instance by name.
<br />
+
<syntaxhighlight lang="lua">
<ul><br />
+
Sprite:set(param, value)
<li>`"x"`</li><br />
+
</syntaxhighlight>
<li>`"y"`</li><br />
+
 
<li>`"z"`</li><br />
+
 
<li>`"rotation"`</li><br />
+
The possible names for '''param''' are:
<li>`"rotationX"`</li><br />
+
*''"x"''
<li>`"rotationY"`</li><br />
+
*''"y"''
<li>`"scaleX"`</li><br />
+
*''"z"''
<li>`"scaleY"`</li><br />
+
*''"rotation"''
<li>`"scaleZ"`</li><br />
+
*''"rotationX"''
<li>`"alpha"`</li><br />
+
*''"rotationY"''
<li>`"redMultiplier"`</li><br />
+
*''"scaleX"''
<li>`"greenMultiplier"`</li><br />
+
*''"scaleY"''
<li>`"blueMultiplier"`</li><br />
+
*''"scaleZ"''
<li>`"alphaMultiplier"`</li><br />
+
*''"alpha"''
<li>`"anchorX"`</li><br />
+
*''"redMultiplier"''
<li>`"anchorY"`</li><br />
+
*''"greenMultiplier"''
<li>`"anchorZ"`</li><br />
+
*''"blueMultiplier"''
</ul><br />
+
*''"alphaMultiplier"''
<br /></translate>
+
*''"anchorX"''
<source lang="lua">
+
*''"anchorY"''
Sprite:set(param,value)
+
*''"anchorZ"''
</source>
+
 
=== <translate>Parameters</translate> ===
+
=== Parameters ===
'''param''': (string) <translate>The name of the parameter</translate> <br/>
+
'''param''': (string) the name of the parameter<br/>
'''value''': (number) <translate>The new value of the specified parameter</translate> <br/>
+
'''value''': (number) the new value of the specified parameter<br/>
=== <translate>Examples</translate> ===
+
 
'''Example'''<br/>
+
=== Examples ===
<source lang="lua">-- the following two lines do the same thing
+
<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 15:33, 13 July 2023

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"
  • "scaleX"
  • "scaleY"
  • "scaleZ"
  • "alpha"
  • "redMultiplier"
  • "greenMultiplier"
  • "blueMultiplier"
  • "alphaMultiplier"
  • "anchorX"
  • "anchorY"
  • "anchorZ"

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