Sprite:set: Difference between revisions

From GiderosMobile
Created page with "__NOTOC__ '''Available since:''' Gideros 2011.6<br/> === Description === <br /> Sets the specified property of this sprite instance by its name. These names are supported:<br..."
 
No edit summary
 
(16 intermediate revisions by 3 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
'''Available since:''' Gideros 2011.6<br/>
'''Available since:''' Gideros 2011.6<br/>
'''Class:''' [[Sprite]]<br/>
=== Description ===
=== Description ===
<br />
Sets the values of a sprite instance by name.
Sets the specified property of this sprite instance by its name. These names are supported:<br />
<syntaxhighlight lang="lua">
<br />
Sprite:set(param, value)
<ul><br />
</syntaxhighlight>
<li>`"x"`</li><br />
 
<li>`"y"`</li><br />
The possible names for '''param''' are:
<li>`"z"`</li><br />
*''"x"''
<li>`"rotation"`</li><br />
*''"y"''
<li>`"rotationX"`</li><br />
*''"z"''
<li>`"rotationY"`</li><br />
*''"rotation"''
<li>`"scaleX"`</li><br />
*''"rotationX"''
<li>`"scaleY"`</li><br />
*''"rotationY"''
<li>`"scaleZ"`</li><br />
*''"scale"''
<li>`"alpha"`</li><br />
*''"scaleX"''
<li>`"redMultiplier"`</li><br />
*''"scaleY"''
<li>`"greenMultiplier"`</li><br />
*''"scaleZ"''
<li>`"blueMultiplier"`</li><br />
*''"anchorX"''
<li>`"alphaMultiplier"`</li><br />
*''"anchorY"''
<li>`"anchorX"`</li><br />
*''"anchorZ"''
<li>`"anchorY"`</li><br />
*''"alpha"''
<li>`"anchorZ"`</li><br />
*''"redMultiplier"''
</ul><br />
*''"greenMultiplier"''
<br />
*''"blueMultiplier"''
<source lang="lua">
*''"alphaMultiplier"''
= Sprite:set(paramvalue,)
*''"skewX"''
</source>
*''"skewY"''
'''param:''' (string) The name of the parameter ''''''<br/>
 
'''value:''' (number) The new value of the specified parameter ''''''<br/>
=== Parameters ===
'''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
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)
</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