Dynamic clouds either too fast or disappearing

  • #1, by tom-barnetThursday, 25. November, 12:02 A week ago
    Hi everybody,

    I have absolutely zero knowledge of Lua script, however, I have tried reverse engineering to implement dynamic clouds into my game according to this tutorial LINK. I have been almost successful except for one thing - the clouds in my game flow either very quickly across the screen or when I slow them down, they disappear halfway through it. By trial and error, I found out, I can change the speed of the clouds in scene Action "dyn_cloud_i_loop"

    local delay = math.floor(Values["v_cloud_1_delay"].Int / 100)  * getPos("cloud_1", -1181, 1280)
    1

    By changing the number after .Int/ or by changing the number in Set random value in "v_cloud_delay". However, in both cases, the clouds then disappear halfway on the screen. I should also state, that the original tutorial is made for screen 640px wide, and my game is 1280, i suspect that may play a role as well. Is there the original author of the scripts or someone who understand Lua, that could please help me sort this out and make my clouds "live" untill they make it all the way across the screen? (i did account the width of my screen within the scripts and where the clouds are suppesd to move)

    Newbie

    15 Posts


  • #2, by esmeraldaThursday, 25. November, 17:19 A week ago
    Is there a reason why you are calculating the delay by multiplying a random value with the positon of the cloud?
    Wouldn't a random value be enough?
    (disclaimer - I haven't looked at the linked example file)

    Great Poster

    439 Posts

  • #3, by SimonSThursday, 25. November, 17:28 A week ago
    The example is written by Lee and it seems it's a bit complicated.

    You probably don't need as much randomness, maybe it's easier to do all of this with just one action:
    ActiveAnimations["cloud_1"].CurrentPosition = {x=-500,y=0}
    ActiveAnimations["cloud_1"]:to(2000, {CurrentPosition = {x = 980, y = 0}}, easeLinearIn, true, false)
    1
    2

    It just sets the cloud to a starting position and moves it to the end position, that repeats automatically with the true at the end. The false is for reversing, you probably don't want that.

    Thread Captain

    1477 Posts

  • #4, by tom-barnetThursday, 25. November, 19:23 A week ago
    Simon, thank you so much, this is perfect and works like a charm! I didn't need anything too complicated and this does the job just fine.

    Esmeralda, I have no idea, the script is not written by me and i do not know Lua :-)

    Newbie

    15 Posts

  • #5, by tom-barnetThursday, 25. November, 20:30 A week ago
    One more thing: Is there a way to make the clouds begin in the middle of the screen at first and only after that appear from the edge of the screen (from the second cycle on)?

    Newbie

    15 Posts

  • #6, by afrlmeThursday, 25. November, 21:14 A week ago
    Yeah my example was a bit complicated, but it was to randomize which cloud was shown each loop & how fast it would travel to make it feel more dynamic as opposed to the same thing repeating in an endless loop.

    Another method that could be done now (since Lua draw didn't exist probably back when I created that example) would be to use Lua draw to draw random clouds at different speeds across the scene.

    Imperator

    7042 Posts

  • #7, by SimonSFriday, 26. November, 11:24 A week ago
    One more thing: Is there a way to make the clouds begin in the middle of the screen at first and only after that appear from the edge of the screen (from the second cycle on)?
    You need two tweens for that, and the real animation after the first one.
    ActiveAnimations["cloud_1"].CurrentPosition = {x=300,y=0}
    ActiveAnimations["cloud_1"]:to(1200, {CurrentPosition = {x = 980, y = 0}}, easeLinearIn)
    setDelay(1200, function()
      ActiveAnimations["cloud_1"].CurrentPosition = {x=-500,y=0}
      ActiveAnimations["cloud_1"]:to(2000, {CurrentPosition = {x = 980, y = 0}}, easeLinearIn, true, false)
    end)
    1
    2
    3
    4
    5
    6

    Thread Captain

    1477 Posts

  • #8, by tom-barnetFriday, 26. November, 16:28 A week ago
    Thank you Simon. However my clouds keep disappearing (restarting i guess) in hlafway through the screen.  Where am I making mistake?

    In my case, the screen is 1280 px wide and the clouds are flowing from the right to the left. I slowed them down by changing the value in line 5 ActiveAnimations["cloud_1"]:to(2000 to 40000. When I additionally changed the value of the setDelay(1200, function() to 20000 or so, it worked for a while, but when I returned to the menu from playing a level  the clouds just kept disappearing.

    Newbie

    15 Posts

  • #9, by SimonSFriday, 26. November, 16:35 A week ago
    Please post your current code. The setDelay time should be the same as the first tween. 

    Thread Captain

    1477 Posts

  • #10, by tom-barnetMonday, 29. November, 16:11 5 days ago
    Thanks again Simon, it appears the problem of the disappearing clouds was caused by me having different values in the setDelay time. The current code is as follows and seems to be working without any trouble:

    ActiveAnimations["cloud_1"].CurrentPosition = {x=300,y=0}
    ActiveAnimations["cloud_1"]:to(70000, {CurrentPosition = {x = -824, y = 0}}, easeLinearIn)
    setDelay(70000, function()
      ActiveAnimations["cloud_1"].CurrentPosition = {x=1280,y=0}
      ActiveAnimations["cloud_1"]:to(70000, {CurrentPosition = {x = -824, y = 0}}, easeLinearIn, true, false)
    end)
    1
    2
    3
    4
    5
    6

    Newbie

    15 Posts

Write post