-- UPDATED WITH PARALLAX SNOW
-- Displaybar
display.HiddenStatusBar = true
-- create table
local stars = {}
local snow_layer = display.newRect(0,480,320,480)
snow_layer:setFillColor(255,255,255)
local snow_text = display.newText("MERRY CHRISTMAS, AND SHAKE ME!!",50,100)
snow_text:setTextColor(255,255,255)
-- initial vars
local stars_total = 200
local star_width = 3
local star_height = 3
-- create/draw objects
for i = 1, stars_total do
local star = {}
star.object = display.newCircle(math.random(320),math.random(480),star_width,star_height)
stars[ i ] = star
end
-- update star locations and setcolor
local function udpdatestars(event)
for i = stars_total,1, -1 do
-- define default snow colors
r = 255
g = 255
b = 255
starspeed = 2
if (i>100) then
r = 155
g = 155
b = 155
starspeed = 1
end
stars[i].object:setFillColor(r,g,b)
stars[i].object.y = stars[i].object.y + starspeed
if (stars[i].object.y > display.stageHeight) then
stars[i].object.y = stars[i].object.y-480
end
end
end
function snow_layer:timer( event )
local count = event.count
self.y = self.y-1
end
local function shakeme( event )
if (event.isShake) then
snow_layer.y = 720
end
end
-- let updatestars run at enterFrame
Runtime:addEventListener("accelerometer",shakeme)
Runtime:addEventListener("enterFrame",udpdatestars)
timer.performWithDelay( 100, snow_layer, 480 )
-- Enjoy it
-- Frehsworks
Cool - I'll give it a shake!
It works beautifully on my Mac, but still has the jerky effect on my iTouch ... :(