Hi guys,
I have a steering wheel on my screen which the user rotates to rotate his ship. The wheel is a physics object as I want to continue spinning even after the user has released the touch event.
At the moment I am applying a rotational force to the wheel every time the player moves his finger on the wheel. And I’m applying a fraction of this force to the ship also (more turns of the wheel needed to turn the ship).
I THINK this is causing performance issues because the iPad I am testing on keeps lagging whenever the wheel is moved, skipping frames etc.
Anyone got any ideas on a solution/alternative approach?
Here is the code for the Wheel touch event:
-- Function to handle when wheel is touched handleWheelTouch = function(event) local wheel = event.target -- Limits the wheel so it can only turn two degrees per frame local limitPerFrame = 2 if event.phase == "began" then display.getCurrentStage():setFocus(wheel, event.id) -- Store initial position of finger wheel.x1 = event.x wheel.y1 = event.y elseif event.phase == "moved" then wheel.x2 = event.x wheel.y2 = event.y local pi, iTan = math.pi, math.atan2 local angle1 = 180/pi \* iTan(wheel.y1 - wheel.y , wheel.x1 - wheel.x) local angle2 = 180/pi \* iTan(wheel.y2 - wheel.y , wheel.x2 - wheel.x) wheel.rotationAmt = angle1 - angle2 if wheel.rotationAmt \< -limitPerFrame then wheel.rotationAmt = -limitPerFrame elseif wheel.rotationAmt \> limitPerFrame then wheel.rotationAmt = limitPerFrame end wheel:applyAngularImpulse( -wheel.rotationAmt\*2 ) -- Dispatch Rotate Event dispatchWheelRotate(wheel.angularVelocity) wheel.x1 = wheel.x2 wheel.y1 = wheel.y2 elseif event.phase == "ended" then display.getCurrentStage():setFocus(nil) wheel.isFocus = false end -- Stop further propagation of touch event return true end