fanadventures.net

Header
English
 
Forum overview > Creating a sky with blinking stars
  • Creating a sky with blinking stars

    by tor.brandt · Thursday, 13. October 2016, 12:22 h ~ 11 months ago
    Hi all

    I have a scene background with a starry sky, and I'd like the stars to blink randomly.
    I guess one solution could be to make all the stars objects, and then randomize their animations with a script.
    However, I'd like to hear if anyone has an idea for a better solution that I haven't thought of?

    Thanks!
    tor.brandt
  • by ke4 · Thursday, 13. October 2016, 13:14 h ~ 11 months ago
    I'm not sure if there's better solution. Maybe by using the particle system. In the upcoming version will be more user frendly tools for creating particles.

    The script should be easy enough, but it depends on how much of the stars you would like to blink at the same time. Not sure if there's still no option for positioning objects absolutely with Lua so you would need to use animation instead.

    I guess you could do something like:

    Set random value in "random_time" between 500 to 5000
    Pause for random_time miliseconds
    play animation "star_blink"

    ActiveAnimations["star_blink"]:to(0, { CurrentPosition = {x = math.random(0,1920), y = math.random(0,1080)} }, easeQuintOut)

    1

    Jump to actionpart#1

    To put the animation randomly on screen with resolution 1920x1080.
    ke4
  • by AFRLme · Thursday, 13. October 2016, 13:52 h ~ 11 months ago
    @ Ke4: I think that would be a bit too random as they could end up all clumped more over in one spot.

    I recommend creating a single static image. Creating a loop & having it randomly adjust the opacity over x random time. It's simple but very effective. Check out this tutorial I wrote a while back on dynamic lighting. You should find it useful.

    Another thing you could consider to liven it up a bit is maybe consider having some birds / bats fly across the sky every x random time or maybe a shooting star fizzle in & fade out as it dives downwards.
    AFRLme
  • by tor.brandt · Thursday, 13. October 2016, 14:47 h ~ 11 months ago
    Thanks for the replies!

    @Ke4: I think I might have been too unspecific with what I'm after.
    What I want is for all the stars to be in same spots at all times, while each star blinks randomly. I.e. each star is a static image most of the time, and then plays a single loop of blinking animation now and then.

    @AFRLme:
    I have the background as a static image, and right now I'm trying out having all the stars as objects. But of course it seems pretty laborous to place each single star as an object in itself, and have it animate randomly with a script.

    Do you mean I should create a single static image containing all the stars?
    And if so, can the random opacity adjustment then be carried out on only specific areas of that image, or how does that work?

    I'll take a look at your tutorial.
    tor.brandt
  • by tor.brandt · Thursday, 13. October 2016, 15:12 h ~ 11 months ago
    Hmm... Actually, I think I should be even more specific:

    I'd like the blinking of each star to be an animation consisting of 4 frames:
    Frame 1 is the star without a "corona", frame 2 is the star with some corona, frame 3 is the star with even more corona, and frame 4 is the same as frame 2.
    I've put in this script (that I found somewhere on the forum, I forgot where) in frame 1:


    if math.random(200) < 10 then
    ActiveAnimations["star_blinking"].AnimationLastFrame = 4
    else
    ActiveAnimations["star_blinking"].AnimationLastFrame = 1
    end

    1
    2
    3
    4
    5


    This works exactly right for a single star. But it seems pretty tedious to make a unique object with its own unique animation ("star_x_blinking") for each star, as I'd like to have around 70 stars.

    Does anyone have an idea for how I could get around this, or have a smarter way to do it with the same visual result?

    Thanks!
    tor.brandt
  • by AFRLme · Thursday, 13. October 2016, 15:13 h ~ 11 months ago
    Ah no, you might want to create a few layers if you want to make it a little more dynamic. 2 or 3 layers should be enough.

    What I suggested works by creating a looping action block at the beginning of the scene. You also need 2 values per image you want to affect. 1 for setting a random pause / delay value (time it should take to switch from the current opacity value to the target opacity value) & another value for randomizing the opacity value. The random value for the delay should be something between I don't know, let's say 500ms & 1000ms (you'll have to play around with the numbers to get something you like) & the random value for the opacity should be set to something like min 50% max 100% - you don't want to go too low.

    Anyway, what you need to do is something like this...



    Of course there's a little more to it than that as you need to make sure you kill the loop manually at the end of the scene (you can do so inside of an "at end of scene" action) & you also need to start the loop by calling the relevant action inside of an "at begin of scene" action.

    You should be able to figure it out from the tutorial I linked you with earlier.

    P.S: if you want to apply easing to the fade in/out then you will need to adjust the opacity value with Lua script instead of the action part. The screenshot I shared above was a pure action part method without needing to resort to Lua script.

    P.S: what you are proposing with 4 different frames per star sounds very tedious (as you put it) & completely overkill. Hardly anyone will notice such a subtle thing - except the odd few people like me that pay attention to detail - & that's the odd few, so you might as well think simpler as most people tend to focus on the task at hand rather than absorbing in every single minute detail of a games artwork. I recommend livening up your scenes with subtle environment animations here or there. Maybe some kind of animal or piece of machinery in the background. Floating dust particles. Clouds that slowly move across the sky, etc - speaking of moving clouds I created a tutorial for that as well in the tutorial section of the wiki.
    AFRLme
  • by tor.brandt · Thursday, 13. October 2016, 15:31 h ~ 11 months ago
    @AFRLme:

    Thanks a lot for your comments!
    I'm totally new to Visionaire, and pretty much a beginner at coding too, so I'm not sure if I totally understand what your'e saying yet, but I'll study your tutorial some more, as well as your posts.

    And regarding your last P.S.: I notice too, and that's enough for me to want to make it exactly right. Also, I'm working with a very minimalist artwork (I like minimalism), so I want the few elements there are to be perfect. And finally, the scene I'm working on is going to be a start menu, so I think it's worth it to put in some extra effort smile
    tor.brandt
  • by AFRLme · Thursday, 13. October 2016, 15:52 h ~ 11 months ago
    Ah ok understood. Maybe you could group up some of the stars into layers? I don't mean all the stars in one specific quadrant but maybe pick random stars so you end up with a few layers that you can control the animation of independently.

    Technically you could run a for loop to dynamically control the animation frame of each star if you really want, but it would still require a lot of time to manually create an object for each star, link an animation to it & then position it where you want it in the scene. I do not recommend importing an animation that includes a canvas the size of your games default resolution as it would be wasting valuable system resources. As for the animations & scene objects containing the star animations, they should all have the same name, something like "star_1", "star_2", "star_3", etc (note the number prefix on the end.

    Next you could create a loop like I mentioned above to run a for loop every random amount of time to switch up the star animations.

    local rand

    for i = 1, 70 do
    rand = math.random(1,4) -- generate random value between 1 & 4
    game.CurrentScene.SceneObjects["star_" .. i].ObjectAnimations["star_" .. i].AnimationFirstFrame = rand -- force initial frame of animation i to random value
    game.CurrentScene.SceneObjects["star_" .. i].ObjectAnimations["star_" .. i].AnimationFirstFrame = rand -- force end frame of animation i to random value
    end

    1
    2
    3
    4
    5
    6
    7

    ... basically what we are doing in that script example is iterating through all the animations & forcing it to loop a specific frame by setting the first & last frame to the same value.
    AFRLme
  • by tor.brandt · Thursday, 13. October 2016, 15:58 h ~ 11 months ago
    @AFRLme:

    Thanks again!
    I think maybe the best solution for me is, like you suggest, to divide the stars into groups and randomize the animations of those groups.
    5-10 objects of star groups are still a lot better than 70 objects of unique stars! smile
    tor.brandt
  • New post