Hi
Can I call a function or what the function return from another function ?
For example :
local dragItem=function(event)
t= event.target
…
…
From another function :
local rotate = function(event)
…
…
…
object.rotation = dragItem(t).rotation or dragItem(event.target).rotation or something like this.
I’am a beginner please forgive me if it’s stupid.
A link or a any trace or example will be great
Thank you [import]uid: 13156 topic_id: 5753 reply_id: 305753[/import]
Thanks slimboyfat but what when both depends of events. Drag event move the object and showing a gear (circle) around but rotate rotating the object that you touch before via touching a gear.
[code]
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
dragItem(event.target).rotation = gear.rotation----- I want compare gear rotation to event.target from dragItem function
end
gear:addEventListener(“touch”, rotate)
local dragItem = function(event)
local t = event.target
local phase = event.phase
if “began” == phase and ball.isActive == false then
I’m guessing that you want an object to start rotating and start being draged when you touch it?
this should be outside the function, it’s not activated inside the function it’s going to call unless you call the function from elsewhere.
gear:addEventListener("touch", dragItem)
local rotate = function(event)
local xOffset = gear.x
local yOffset = gear.y
local angleBetween = mCeil(mAtan2( (event.y - yOffset), (event.x - xOffset) ) \* 180 / math.pi) + 90
gear.rotation = angleBetween + 180
end
local dragItem = function(event)
if(event.phase=="began") then
Runtime:addEventListener("enterFrame", rotate)
elseif (event.phase=="ended" or event.phase="cancelled") then
Runtime:removeEventListener("enterFrame", rotate)
elseif(event.phase=="moving") then
event.target.x = event.x
event.target.y = event.y
end
end
gear:addEventListener("touch", dragItem)
Can’t test the code now but something like this should work, I’m a novice to so sorry if it doesn’t work [import]uid: 9577 topic_id: 5753 reply_id: 19724[/import]