polylines 1.0 sample code

I was looking at the polylines simple example (with downloaded corona sdk) :

  
--   
-- Abstract: PolyLines sample app, demonstrating how to draw shapes using line segments  
--   
-- Version: 1.0  
--   
-- Sample code is MIT licensed, see http://developer.anscamobile.com/code/license  
-- Copyright (C) 2010 ANSCA Inc. All Rights Reserved.  
-- Example of shape drawing function  
local function newStar()  
  
 -- need initial segment to start  
 local star = display.newLine( 0,-110, 27,-35 )   
  
 -- further segments can be added later  
 star:append( 105,-35, 43,16, 65,90, 0,45, -65,90, -43,15, -105,-35, -27,-35, 0,-110 )  
  
 -- default color and width (can also be modified later)  
 star:setColor( 255, 255, 255, 255 )  
 star.width = 3  
  
 return star  
end  
-- Create stars with random color and position  
local stars = {}  
  
for i = 1, 5 do  
  
 local myStar = newStar()  
  
 myStar:setColor( math.random(255), math.random(255), math.random(255), math.random(200) + 55 )  
 myStar.width = math.random(10)  
  
 myStar.x = math.random( display.contentWidth )  
 myStar.y = math.random( display.contentHeight )  
 myStar.rotation = math.random(360)  
  
 myStar.xScale = math.random(150)/100 + 0.5  
 myStar.yScale = myStar.xScale  
  
 myStar:setReferencePoint( display.CenterReferencePoint )  
  
 local dr = math.random( 1, 4 )  
 myStar.dr = dr  
 if ( math.random() \< 0.5 ) then  
 myStar.dr = -dr  
 end  
  
 table.insert( stars, myStar )  
end  
function stars:enterFrame( event )  
  
 for i,v in ipairs( self ) do  
 v.rotation = v.rotation + v.dr  
 end  
end  
  
Runtime:addEventListener( "enterFrame", stars )  

My question is simple : how would add the following feature :
On tap, all stars stop/resume.

This will help me to understand how to navigate through stars{}, kind of as3 arrays.

Thx for any hints. [import]uid: 9328 topic_id: 4680 reply_id: 304680[/import]

without much though into it

[code]


– Abstract: PolyLines sample app, demonstrating how to draw shapes using line segments

– Version: 1.0

– Sample code is MIT licensed, see http://developer.anscamobile.com/code/license
– Copyright © 2010 ANSCA Inc. All Rights Reserved.
– Example of shape drawing function
local function newStar()

– need initial segment to start
local star = display.newLine( 0,-110, 27,-35 )

– further segments can be added later
star:append( 105,-35, 43,16, 65,90, 0,45, -65,90, -43,15, -105,-35, -27,-35, 0,-110 )

– default color and width (can also be modified later)
star:setColor( 255, 255, 255, 255 )
star.width = 3

return star
end
– Create stars with random color and position
local stars = {}

local rotate = 1; – << ADD THIS
for i = 1, 20 do

local myStar = newStar()

myStar:setColor( math.random(255), math.random(255), math.random(255), math.random(200) + 55 )
myStar.width = math.random(10)

myStar.x = math.random( display.contentWidth )
myStar.y = math.random( display.contentHeight )
myStar.rotation = math.random(360)

myStar.xScale = math.random(150)/100 + 0.5
myStar.yScale = myStar.xScale

myStar:setReferencePoint( display.CenterReferencePoint )

local dr = math.random( 1, 4 )
myStar.dr = dr
if ( math.random() < 0.5 ) then
myStar.dr = -dr
end

table.insert( stars, myStar )
end

– << ADD THIS >>----
function stars:tap(event)
if ( rotate == 0 ) then
rotate = 1
else
rotate = 0
end
end

– << ADD ABOVE >> –

function stars:enterFrame( event )

if ( rotate == 1 ) then – << ADD THIS

for i,v in ipairs( self ) do
v.rotation = v.rotation + v.dr
end

end – << ADD THIS
end
Runtime:addEventListener( “tap”, stars) – << ADD THIS
Runtime:addEventListener( “enterFrame”, stars )
[/code] [import]uid: 24 topic_id: 4680 reply_id: 14809[/import]

Thx for your blazing fast answer.
It works like a charm.

A research on ipairs helped me to better understand how you cycle through the array.

There is another thing I don’t understand :
If I change

function stars:tap(event)  
...  
Runtime:addEventListener( "tap", stars)  

to

function otherFunctionName:tap(event)  
...  
Runtime:addEventListener( "tap", otherFunctionName)  

The simulator returns an error.
Why the function name must be the array’s name (stars) ?

[import]uid: 9328 topic_id: 4680 reply_id: 14819[/import]