scrolling stack I made
Geoff Canyon
gcanyon at gmail.com
Wed May 22 10:28:09 EDT 2013
Hi Colin,
Nice work!
I added timing code to get the framerate. On my macbook pro when nothing is
actually moving, it achieves about 40 fps. When the images are moving it
drops to about 24 fps. I'd be curious how using the move command might
compare. I don't think it would be faster since with each frame it's
likely that all the commands would have to be canceled and re-issued to
change the speed.
I also simplified the movement routine to a single line to update the
position of each object, which eliminated the need to store the position in
the array. Feel free to use anything or nothing from this:
global places,worldx,difx
local frameratecounter,secondmarker
on opencard
resetobjects
put 0 into difx
if the environment is mobile then mobileEnableAccelerometer 100
moveworld
end opencard
on accelerationChanged pXAccel, pYAccel, pZAccel
put min(100,max(-100,pYAccel*10)) into difx
end accelerationChanged
on moveworld
if the environment is not mobile then
put (512-the mouseh)/100 into difx
end if
movethings difx
add 1 to frameratecounter
if seconds() is not secondmarker then
put frameratecounter
put 0 into frameratecounter
put seconds() into secondmarker
end if
if the optionkey is not down then send moveworld to me in 16 milliseconds
end moveworld
on resetobjects
lock screen
put 0 into oldvalue
put 0 into worldx
put "" into places
split places by return
addimage "lc1",the left of img "lc1",8
repeat with a = 1 to 100
put "lc_"&a into imagename
if there is not an image imagename then
clone image "lc1"
set the name of image the number of images to imagename
end if
set the width of image imagename to min(256,1024/min(101-a,100))
set the height of image imagename to min(256,1024/min(101-a,100))
set the top of image imagename to random(500)
set the left of image imagename to random(2048)
addimage imagename,the left of image imagename,min(10+(101-a) / 3,100)
end repeat
addimage "sky1",0,60
addimage "sky2",1024,60
addimage "hills1",0,40
addimage "hills2",1024,40
addimage "tracks1",0,20
addimage "tracks2",1024,20
addimage "farhedges1",0,10
addimage "farhedges2",1024,10
addimage "nearhedges1",0,5
addimage "nearhedges2",1024,5
movethings worldx
repeat with a = 1 to the number of images
set the layerMode of img a to dynamic
end repeat
unlock screen
end resetobjects
on addimage imagename, imageplace, imagespeed
put imagename into places[imagename]["imagename"]
set the left of image imagename to imageplace
put imagespeed into places[imagename]["imagespeed"]
end addimage
on movethings howmuch
lock screen
repeat for each element a in places
set the left of image a["imagename"] to trunc(3072 + the left of
image a["imagename"] + howmuch*100/a["imagespeed"]) mod 2048 - 1024
end repeat
unlock screen
end movethings
More information about the use-livecode
mailing list