How to make twinkling stars?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
17 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"
by | 17 views

3 Answers

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

Related questions

0 like 0 dislike
3 answers
asked May 20, 2019 by Meksvinz
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked Jun 10, 2019 by vovchik3003
110,608 questions
257,186 answers
0 comments
35,649 users