Just wondering if anybody knows how to recreate the touch lever action ?
http://www.wired.com/geekdad/wp-content/uploads/2011/08/JJ-jackpot.jpg
Just wondering if anybody knows how to recreate the touch lever action ?
http://www.wired.com/geekdad/wp-content/uploads/2011/08/JJ-jackpot.jpg
Don't know what the exact animation is but if you have to pull the lever down to activate and not just click on the lever, then you need to get the initial touch position and compare it to the final touch position. The percentage of where the current touch is between the 2 start and end positions dictates what frame of the animation is being used.
So, say you have 10 frames in your lever animation:
function lengthOf(a, b)
local width, height = b.x-a.x, b.y-a.y
return (width*width + height*height)^0.5
end
local startBox, endBox
local beingPulled = false
if isOver(touchPos, startBox) and touch.phase == "began" then
beingPulled = true
end
if touch.phase == "moved" then
if beingPulled then
local lengthA = lengthOf(touch, startBox)
local lengthB = lengthOf(touch, endBox)
local totalLength = lengthA+lengthB
local percentage = totalLength/lengthA
lever:setFrame( math.ceil(percentage*10) )
end
end
if touch.phase == "ended" then
lever:resetPosition()
beingPulled = false
end
You will either need 3d Object, which can be rotated a bit - to make that animation, or You could already pre-render all animation frames on animating an object (for example - You have a "lever" object).
I've done something similar - I had pre-rendered images of a rotating cube. I set all these images as animation frames like in this example: http://appsamuck.com/day2.html
And I placed invisible scrollView above this UIImageView
. Then , when scrollViewDidScroll
was called - I simply changed current UIImageView
animation frame.
So in this case - it could be a UIScrollView
, which on - for example:
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
would setContentOffset to CGPoint(0,0)
point. (with animation).
Thats my proposal. Good luck!