Difference between revisions of "Sprite:setRotation"

From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(One intermediate revision by the same user not shown)
Line 5: Line 5:
 
=== Description ===
 
=== Description ===
 
Sets the rotation of the sprite in degrees.
 
Sets the rotation of the sprite in degrees.
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
Sprite:setRotation(rotation)
 
Sprite:setRotation(rotation)
</source>
+
</syntaxhighlight>
  
 
=== Parameters ===
 
=== Parameters ===
Line 13: Line 13:
  
 
=== Example ===
 
=== Example ===
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
-- let's define a pixel and add it to the stage
 
-- let's define a pixel and add it to the stage
 
local mypixel = Pixel.new(0xff0000, 1, 64, 64)
 
local mypixel = Pixel.new(0xff0000, 1, 64, 64)
Line 31: Line 31:
 
timer:addEventListener(Event.TIMER, onTimer, timer)
 
timer:addEventListener(Event.TIMER, onTimer, timer)
 
timer:start()
 
timer:start()
</source>
+
</syntaxhighlight>
  
 
{{Sprite}}
 
{{Sprite}}

Latest revision as of 14:33, 13 July 2023

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()