Hi all,
For the past few days I’ve been trying to rebuild what I did in GameSalad in Corona. At the very beginning what seemed to be an easy project proved to be way harder than I thought. Here is what I did in GS;
http://www.youtube.com/watch?v=rQ3oiYnr8Jo
And here is what I did in Corona;
http://www.youtube.com/watch?v=_qg_zUpb1g8
It is pretty close but I can’t get it working while mouse (touch) is moving and pressed. I tried to use timelimit (system.gettimer()) and few other methods but I failed everytime.
Here is my full code;
\_H = display.contentHeight \_W = display.contentWidth local Y2 = 630 local X2 = \_W/2 circle = display.newCircle( X2, Y2, 10 ) markTime = os.time() print ( markTime ) function SpawnBall() --print ( "spawnball" ) circle = display.newCircle( X2, Y2, 10 ) end function MoveBall(event) print ( event.x ) print ( event.y ) local X1 = event.x local Y1 = event.y local m1 = (Y2 - Y1)/(X2 - X1) --The Slope local TargetX = (-2000 - Y2 + ( m1 \* X2 ) ) / m1 --Calculate the Target X coordinate according to Y=2000 coordinate local ballTravelDistance = math.sqrt( ((-2000 - Y2) \* (-2000 - Y2)) + ((TargetX - X2) \* (TargetX - X2)) ) --The distance? transition.to( circle, { time=ballTravelDistance\*3, x=TargetX, y=-2000} ) timer.performWithDelay( 100, SpawnBall) end local amItouching = false local function onScreenTouch(event) markTime = system.getTimer() doit = function() MoveBall(event) end if (event.phase ~= "moved") then if (event.phase == "ended") then amItouching = false print ( amItouching ) elseif (event.phase == "began") then amItouching = true print ( amItouching ) end if (amItouching==true) then cycle = timer.performWithDelay(90, doit, 0) else timer.cancel ( cycle ) end end end --function Runtime:addEventListener( "touch", onScreenTouch )
I know it is a lot to ask to re-write or even to ask to study the code and tell what I’m doing wrong but I just can’t do it and I need help. I already had some awesome people helping me with this code. Maybe I just need to read a lot more tutorials before I do something like this…
