You can add more to your Movie Clip, so it moves off screen on the left when the first animation finishes and then set it to loop using setGotoAction like so:
-- this is assuming your width is 320? I'd use a variable and get --application:getContentWidth() in case you ever change resolutionlocal sprite = Bitmap.new(Texture.new("Cloud1.png"))local mcLR = MovieClip.new{{1, 100, sprite,
{x ={0, 320-sprite:getWidth(), "linear"}}},
{101, 110, sprite,
{x ={-sprite:getWidth(), 0, "linear"}}}}
mcLR:setGotoAction(110,1)
stage:addChild(mcLR)
Oh, the problem is I just threw in the numbers quick to show how it could be done, but we need to calculate how many frames it should actually take vs the rest of the animation. The easiest way to do this honestly would be if your clouds could setup off screen the first time so we can do it in one tween as opposed to 2, like so:
local mc1 = MovieClip.new{{1, 300, sprite1,
{y =10, x ={-sprite1:getWidth(), 320, "linear"}}}}
Otherwise, you would need to calculate how many frames it should take to come in from off screen:
-- 320 pixels in 300 frames, multiply by how many pixels we need to move (the width)local mc1frames =math.floor(320/300* sprite1:getWidth())local mc1 = MovieClip.new{{1, 300, sprite1,
{y =10, x ={0, 320, "linear"}}},
{301, (301+mc1frames), sprite1,
{y =10, x ={-sprite1:getWidth(), 0, "linear"}}}}
mc1:setGotoAction(301+mc1frames,1)
@thanhquan1512: your game is very attractive and I want to simulate clouds like you do. I've attached example based on your class, but it doesn't work!?!? (( Can you check why not??? Thx!
Comments
Likes: bravcm
Thanks!
P.S.
Which tag I must use to display properly lua source code in posts?
And most probably you also need to provide constant y position as:
Likes: bravcm
This is class clsCloud, to use it include this: local clsCloud = require("cloud")
Look at my games for a result https://play.google.com/store/apps/details?id=com.ultimategamestudio.cupidgameoflove
Ultimate Games on Appstore
Ultimate Games on Google Play
@thanhquan1512: your game is very attractive and I want to simulate clouds like you do. I've attached example based on your class, but it doesn't work!?!? (( Can you check why not??? Thx!
Dislikes: DoradoLab
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive