Difference between revisions of "Sprite:setRotation"

From GiderosMobile
(added example)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
 +
 
<languages />
 
<languages />
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
+
 
'''<translate>Class</translate>:''' [[Special:MyLanguage/Sprite|Sprite]]<br/>
+
'''<translate>Available since</translate>:''' Gideros 2011.6
 +
<br/>
 +
 
 +
'''<translate>Class</translate>:''' [[Special:MyLanguage/Sprite|Sprite]]
 +
<br/>
 +
 
 
=== <translate>Description</translate> ===
 
=== <translate>Description</translate> ===
<translate><br />
+
<translate>
Sets the rotation of the sprite in degrees.<br />
+
Sets the rotation of the sprite in degrees.
<br /></translate>
+
</translate>
 +
<br/>
 +
 
 
<source lang="lua">
 
<source lang="lua">
Sprite:setRotation(rotation)
+
Sprite:setRotation(rotation)
 
</source>
 
</source>
 +
 
=== <translate>Parameters</translate> ===
 
=== <translate>Parameters</translate> ===
 
'''rotation''': (number) <translate>rotation of the sprite</translate> <br/>
 
'''rotation''': (number) <translate>rotation of the sprite</translate> <br/>
 +
 +
=== <translate>Example</translate> ===
 +
<source lang="lua">
 +
-- let's define a pixel and add it to the stage
 +
local mypixel = Pixel.new(0xff0000, 1, 64, 64)
 +
mypixel:setAnchorPoint(0.5, 0.5)
 +
mypixel:setPosition(64, 64)
 +
stage:addChild(mypixel)
 +
 +
function onTimer(event)
 +
  -- add 1 degree each time the function is called
 +
  mypixel:setRotation(mypixel:getRotation() + 1)
 +
end
 +
 +
-- create our timer and add an event listener
 +
-- 24 = delay in milliseconds
 +
-- 360 = number of repetitions (here the result is 360 degrees)
 +
local timer = Timer.new(24, 360)
 +
timer:addEventListener(Event.TIMER, onTimer, timer)
 +
timer:start()
 +
</source>
 +
<br/>

Revision as of 22:53, 27 July 2019



Available since: Gideros 2011.6

Class: Sprite

Description

Sets the rotation of the sprite in degrees.

Sprite:setRotation(rotation)

Parameters

rotation: (number) rotation of the sprite

Example

-- let's define a pixel and add it to the stage
local mypixel = Pixel.new(0xff0000, 1, 64, 64)
mypixel:setAnchorPoint(0.5, 0.5)
mypixel:setPosition(64, 64)
stage:addChild(mypixel)

function onTimer(event)
   -- add 1 degree each time the function is called
   mypixel:setRotation(mypixel:getRotation() + 1)
end

-- create our timer and add an event listener
-- 24 = delay in milliseconds
-- 360 = number of repetitions (here the result is 360 degrees)
local timer = Timer.new(24, 360)
timer:addEventListener(Event.TIMER, onTimer, timer)
timer:start()