I am making a game with corona sdk in which stars fall down the screen randomly and until the user loses, see the code:
local composer = require( "composer" )
local scene = composer.newScene()
local createstar = {}
local stars = {}
local timer
local b
local update = {}
local wait = {}
local ie = - 150
function scene:create( event )
local sceneGroup = self.view
end
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if phase == "will" then
elseif phase == "did" then
stars = display.newGroup()
function wait( event )
timer = timer.performWithDelay( 100, createstar, 0)
Runtime:addEventListener('enterFrame', update)
end
timer.performWithDelay( 200, wait)
function createstar()
ie = ie - 300
astar = display.newImage('star.png', math.random( 1, 10) * 33, ie)
stars:insert(astar)
sceneGroup:insert(stars)
end
function update(e)
if(stars ~= nil)then
for i = 1, stars.numChildren do
stars[i].y = stars[i].y + 3
end
end
end
end
end
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if event.phase == "will" then
elseif phase == "did" then
end
end
function scene:destroy( event )
local sceneGroup = self.view
end
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
return scene
Now for my game to work I need to be able to draw lines between each star. That is to say that I need the player to touch each star and when he does then a line is created between the star he touched and the one he touched before that. I know how to draw a line but am not sure how to do it between two objects created with a function. Does anyone know how to do this? Thanks in advance!