Hi guys,
Can anyone please share code for following problem:
- you have a line (display.newLine)
How to rotate it using Tilt (in both directions)?
I am trying to make something like this:
Tnx.
G
Hi guys,
Can anyone please share code for following problem:
How to rotate it using Tilt (in both directions)?
I am trying to make something like this:
Tnx.
G
Get sample here:
http://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2016/01/lineRotation.zip
Or use this code to build your own solution:
local function newTurret( x, y ) local turret = display.newCircle( x, y, 20 ) turret.barrel = display.newLine( x, y, x, y - 30) turret.barrel.strokeWidth = 8 turret.barrel.anchorX = 0 turret.angle = 0 -- variable to hold barrel facing angle function turret.setAngle( self, angle ) self.barrel.rotation = angle self.angle = angle end function turret.getAngle( self ) return self.angle end return turret end local aTurret = newTurret( 100, 100 ) timer.performWithDelay( 30, function() local angle = aTurret:getAngle() angle = angle + 2 aTurret:setAngle( angle ) end, 180)
Thanks roaminggamer!
Excellent!
Get sample here:
http://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2016/01/lineRotation.zip
Or use this code to build your own solution:
local function newTurret( x, y ) local turret = display.newCircle( x, y, 20 ) turret.barrel = display.newLine( x, y, x, y - 30) turret.barrel.strokeWidth = 8 turret.barrel.anchorX = 0 turret.angle = 0 -- variable to hold barrel facing angle function turret.setAngle( self, angle ) self.barrel.rotation = angle self.angle = angle end function turret.getAngle( self ) return self.angle end return turret end local aTurret = newTurret( 100, 100 ) timer.performWithDelay( 30, function() local angle = aTurret:getAngle() angle = angle + 2 aTurret:setAngle( angle ) end, 180)
Thanks roaminggamer!
Excellent!