0 like 0 dislike
28 views
Can anyone help with the code. That is, write to me the algorithm please. The stars twinkled. I do so:
Create white circles(50 pieces) and throw them randomly on the screen. But how can I make them all flicker at the same time not all, and randomly to each separately? I would be the algorithm.
PS To flicker is a function of "fx.alpha"
| 28 views

0 like 0 dislike
For each star, keep the counter.
Each frame count is decremented.
If it is less than a 5 star is increased by 5. If less than 10, for 10, if less than 15 - again at 5.
If less than 0, the counter becomes equal to a random number number (100) + 100.
Total each star will be 15 fps increase and it will be repeated for each after 100-200 frames.
by
0 like 0 dislike
The most realistic option is to make a great prefab, the sprite of the sky in photoshop and output the frame animation.
\rhttps://docs.coronalabs.com/guide/media/spriteAnim...
If the analytical output of a star, it is not enough just to scatter them around the stage randomly, you need to store the position and degree of illumination of each star in the list or array and redraw the frame after changing any parameter.
by
0 like 0 dislike
``local star = {} for i=1,50 do star[i] = display.newCircle(math.random(0,display.contentWidth),math.random(0,display.contentHeight), math.random(1,3)) star[i].anchorX =0.5 star[i].anchorY =0.5 star[i].time = math.random(3,20) star[i].animateUp = function () star[i].x = math.random(0,display.contentWidth) star[i].y = math.random(0,display.contentHeight) transition.to( star[i], { time= star[i].time * 100, alpha = 1, xScale = 1, yScale = 1, onComplete=star[i].animateDown } ) end star[i].animateDown = function () transition.to( star[i], { time= star[i].time * 500, alpha = 0, xScale = 0.01, yScale = 0.01, onComplete=star[i].animateUp } ) end star[i].animateDown() end``
by

0 like 0 dislike