Hey
Here is the code that I use to shoot the ball if different directions and with different force. But you will find the same code almost in the pool sample app here
[lua]–> aim stuff
target = display.newImage( “gfx/target.png” )
target.x = ball.x; target.y = ball.y; target.alpha = 0
– Shoot the cue ball, using a visible force vector
local function ballShot( event )
local t = target
local phase = event.phase
if “began” == phase then
display.getCurrentStage():setFocus( t )
t.isFocus = true
– Stop current cueball motion, if any
–t:setLinearVelocity( 0, 0 )
–t.angularVelocity = 0
target.x = ball.x
target.y = ball.y
startRotation = function()
target.rotation = target.rotation + 4
end
Runtime:addEventListener( “enterFrame”, startRotation )
local showTarget = transition.to( target, { alpha=0.4, xScale=0.4, yScale=0.4, time=200 } )
myLine = nil
elseif t.isFocus then
if “moved” == phase then
if ( myLine ) then
myLine.parent:remove( myLine ) – erase previous line, if any
end
myLine = display.newLine( t.x,t.y, event.x,event.y )
myLine:setColor( 255, 255, 255, 80 )
myLine.width = 8
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
t.isFocus = false
local stopRotation = function()
Runtime:removeEventListener( “enterFrame”, startRotation )
end
local hideTarget = transition.to( target, { alpha=0, xScale=1.0, yScale=1.0, time=200, onComplete=stopRotation } )
if ( myLine ) then
myLine.parent:remove( myLine )
end
physics.start()
– Strike the ball!
ballInMove = true
ball:applyForce( (event.x-t.x)*0.01, (event.y-t.y)*0.01, t.x, t.y)
end
end
– Stop further propagation of touch event
return true
end[/lua] [import]uid: 22737 topic_id: 5808 reply_id: 21550[/import]