Difference between revisions of "Sprite:set"

From GiderosMobile
(added example (is this english?) :-()
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(One intermediate revision by the same user not shown)
Line 5: Line 5:
 
=== Description ===
 
=== Description ===
 
Sets the values of a sprite instance by name.
 
Sets the values of a sprite instance by name.
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
Sprite:set(param, value)
 
Sprite:set(param, value)
</source>
+
</syntaxhighlight>
  
  
Line 34: Line 34:
  
 
=== Examples ===
 
=== Examples ===
<source lang="lua">
+
<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 58:
 
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'''
 
''' A camera that follows the player'''
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
-- GAME LOOP
 
-- GAME LOOP
 
function Level:onEnterFrame(e)
 
function Level:onEnterFrame(e)
Line 70: Line 70:
 
self.camera:set("anchorY", posy / self.camera:getScale())
 
self.camera:set("anchorY", posy / self.camera:getScale())
 
end
 
end
</source>
+
</syntaxhighlight>
  
 
{{Sprite}}
 
{{Sprite}}

Latest revision as of 14: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