I want to rotate an objects from a central point and start/restart this rotation on a touch event.
This code rotates this as I want but if you stop the rotation you cant start it again.
There might be a bug with rotations in Corona.
The top buttons on screen rotate the object, and the button below stops the rotation.
[lua]local physics = require(“physics”)
physics.start()
physics.setGravity(0,2) ;
–Set Background
background = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
background:setFillColor( 255, 255, 255, 255 )
rect = display.newRect(370, 180, 30, 30)
rect:setFillColor(255, 255,50)
rect2 = display.newRect(420, 180, 30, 30)
rect2:setFillColor(55, 55,50)
rect4 = display.newRect(390, 220, 30, 30)
rect4:setFillColor(255, 55,50)
local Velocity=“increase”;
function playerDecreaseVelocityLeft(event)
if event.phase == “began” then
Velocity=“decrease”;
end
end
rect:addEventListener(“touch”, playerDecreaseVelocityLeft)
function playerIncreaseVelocityRight(event)
if event.phase == “began” then
Velocity=“increase”;
end
end
rect2:addEventListener(“touch”, playerIncreaseVelocityRight)
function playerStopVelocity(event)
if event.phase == “began” then
if (Velocity~=“stop”) then
Velocity=“stop”;
elseif (Velocity==“stop”) then
Velocity=“start”;
end
elseif event.phase == “ended” or event.phase == “cancelled” then
–Velocity=“nothing”;
end
end
rect4:addEventListener(“touch”, playerStopVelocity)
local circle = display.newCircle( 125, 200, 10 )
circle:setFillColor( 0, 0, 255, 255 )
physics.addBody( circle, “static”)
–local block = display.newRect(circle.x,circle.y,50,50)
local block = display.newRect(0,0,150,20)
block.x = circle.x + 100
block.y = circle.y
–block.rotation = 45
block:setFillColor( 0, 0, 0, 255 )
physics.addBody( block, “dynamic”)
local block2 = display.newRect(0,0,150,20)
block2.x = circle.x - 100
block2.y = circle.y
–block.rotation = 45
block2:setFillColor( 0, 0, 0, 255 )
physics.addBody( block2, “dynamic”)
myJoint = physics.newJoint( “weld”, circle, block, block.x, block.y )
myJoint2 = physics.newJoint( “weld”, circle, block2, block2.x, block2.y )
local rotateIt = function( event )
if (Velocity==“increase”) then
circle.rotation = circle.rotation + 1
elseif (Velocity==“decrease”) then
circle.rotation = circle.rotation - 1
elseif (Velocity==“stop” ) then
– circle.rotation = 0
end
print (“Velocity=” … Velocity)
end
Runtime:addEventListener( “enterFrame”, rotateIt )[/lua] [import]uid: 138547 topic_id: 26385 reply_id: 326385[/import]