Touch and rotation

Hi
I have a problem with rotating object…
Almost every thing is ok but when I touch the object, gear shows up I can rotate the object while touching gear but when I touch another object and I am rotating it both object are rotating first one and the second one. I know this is problem witch t.rotating = gear.rotating but I don’t know how to resolve this…
Maybe my idea of doing this is wrong, but I thing I’am so close…
Can you help me with this please. I’am a beginner…
Thank You

[code]
local dragItem = function(event)

local t = event.target
local phase = event.phase

if “began” == phase and ball.isActive == false then

display.getCurrentStage():setFocus( t )
t.isFocus = true
t.x0 = event.x - t.x
t.y0 = event.y - t.y
event.target.bodyType = “kinetic”
gear.isVisible = true
gear.alpha = 0.3
gear.x = event.target.x
gear.y = event.target.y
event.target:toFront()

elseif t.isFocus then
if “moved” == phase and ball.isActive == false then
t.x = event.x - t.x0
t.y = event.y - t.y0
gear.x = event.target.x
gear.y = event.target.y

elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil)
t.isFocus = false

if (not event.target.isPlatform ) then
t.isFocus = false

local rotate = function(event)
local xOffset = gear.x
local yOffset = gear.y
local angleBetween = mCeil(mAtan2( (event.y - yOffset), (event.x - xOffset) ) * 180 / mPi) + 90
gear.rotation = angleBetween + 180

T.ROTATION = GEAR.ROTATION !!!
end

event.target.bodyType = “static”
physics.addBody(t, “static” ,{density = 2.0, friction = 1.3, bounce = 0.2,} )
gear:addEventListener(“touch”, rotate)

end
end
end
return true

end

[import]uid: 13156 topic_id: 5541 reply_id: 305541[/import]

anyone ? Please maybe is a small thing…
Thank you :slight_smile: [import]uid: 13156 topic_id: 5541 reply_id: 18883[/import]

This post here instead of: https://developer.anscamobile.com/forum/2011/01/18/bubble-ball-adult-touch-issue

Well, it looks like you’re referring to a specific display object called ‘gear’ and setting it’s rotation value. But it looks like you want this function to be a touch event listener for any object.

It seems to me that the function should be coded to access the object which was touched and refer to that specifically. That object would be passed into the function via the event.target value.

matt [import]uid: 8271 topic_id: 5541 reply_id: 19206[/import]

Yes I was trying to do this but I don’t know how to pass object into the function.
Can you give me an example … Then I can code a rotating function separately with gear and then this rotation compare to the object that user touch… Am I right ?
[import]uid: 13156 topic_id: 5541 reply_id: 19210[/import]

If it is the gear which has the touch event added to it, then that is what should receive the event and that is what you will be modifying.

If you want to modify something else, you’ll have to store a reference to what it is you want to modify.

As your code is, you have hard coded a reference to the gear, so that is what gets changed. [import]uid: 8271 topic_id: 5541 reply_id: 19213[/import]