Hi!
I need to place lots of touch handlers, giving slighty different force to my ball in the game. I know the code for this, but doing it as my code shows below would be way to many lines. I need to place 6 rows of circles, with 10 in each row…
Here’s the code for just 2 of them, just to see what I’m trying to achieve.
I probably should put the x and y parameters in a table, and doing the same thing with the force that going to be applied. But I haven’t figured out how to do this properly. Do I have to have 60 functions in the .lua file for this?
Any help would be highly appreciated!!
Thanks so much!
[lua] local c11 = display.newCircle( 250, 280, 6 )
c11:setFillColor(128,128,128)
local c12 = display.newCircle( 230, 280, 6 )
c12:setFillColor(128,128,128)
function mc11(event)
if (canjump == “true”) then
ball:applyForce( 0, -450, ball.x, ball.y )
ball:applyTorque( 12 )
end
end
function mc12(event)
if (canjump == “true”) then
ball:applyForce( 0, -650, ball.x, ball.y )
ball:applyTorque( 10 )
end
end
c11:addEventListener ( “touch”, mc11 )
c12:addEventListener ( “touch”, mc12 )[/lua] [import]uid: 187595 topic_id: 32202 reply_id: 332202[/import]
Fortunately you can accomplish your goal with 1 function.