It's snowing and shake example (updated)

3 replies [Last post]
freshworks
User offline. Last seen 6 weeks 6 days ago. Offline
Joined: 25 Aug 2009

-- 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

Replies

willsingleton
User offline. Last seen 13 weeks 6 days ago. Offline
Joined: 3 Sep 2009

Cool - I'll give it a shake!
It works beautifully on my Mac, but still has the jerky effect on my iTouch ... :(

cditto
User offline. Last seen 1 year 23 weeks ago. Offline
Joined: 7 Jan 2010

Worked great! Thanks for contributing this. I used it to learn how to implement shake code.

chadscc
User offline. Last seen 1 year 27 weeks ago. Offline
Joined: 7 Oct 2009

Yes...thanks...this is a good demo of using shake! Thanks for sharing!

Viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.