thanks for replying, i already figured out what i wanted done
here is the code, if anyone is interested…
[lua]display.setStatusBar( display.HiddenStatusBar )
local physics = require ( “physics” )
physics.start( )
–physics.setDrawMode( “hybrid” )
local _W = display.contentWidth
local _H = display.contentHeight
local label = display.newText( “”, 0, 0, native.systemFont, 20 )
label.x = _W * 0.5
label.y = _H * 0.1
local label2 = display.newText( “drag blue circle towards red circle”, 0, 0, native.systemFont, 20 )
label2.x = _W * 0.5
label2.y = _H * 0.9
local body = display.newRect( 0, 0, 50, 50 )
body.x = _W * 0.5
body.y = _H * 0.2
local btn_anchor = display.newCircle( _W * 0.5 , _H * 0.8, 10 )
btn_anchor:setFillColor( 255, 0, 0, 255 )
physics.addBody( btn_anchor, “static”, { isSensor = true, radius = 10 } )
local btn_main = display.newCircle( _W * 0.5 , _H * 0.8, 30 )
btn_main:setFillColor( 0, 0, 255, 100 )
physics.addBody( btn_main, “dynamic”, { radius = 30 } )
btn_main:addEventListener( “touch”,
function( event )
local phase = event.phase
local self = event.target
local stage = display.getCurrentStage( )
if phase == “began” then
stage:setFocus( self )
self.tempJoint = physics.newJoint( “touch”, self, event.x, event.y )
elseif phase == “moved” then
self.tempJoint:setTarget( event.x, event.y )
elseif phase == “ended” or phase == “cancelled” then
stage:setFocus( nil )
self.tempJoint:removeSelf( )
end
end )
local btn_main_spring = physics.newJoint( “piston”, btn_anchor, btn_main, btn_anchor.x, btn_anchor.y, 0, -1 )
btn_main_spring.isMotorEnabled = true
btn_main_spring.motorSpeed = 1000
btn_main_spring.maxMotorForce = 5
btn_main_spring.isLimitEnabled = true
btn_main_spring:setLimits( 0, 200 )
function enterFrame( )
local speed = ( 200 - ( btn_anchor.y - btn_main.y ) ) * 0.05
label.text = speed
body.rotation = body.rotation + ( 5 * speed )
end
Runtime:addEventListener( “enterFrame”, enterFrame )[/lua] [import]uid: 114118 topic_id: 21077 reply_id: 83265[/import]