Cloud/smoke effect?

Hi all,

I’m in the middle of coding a childrens interactive book, and I would love to add drifting clouds into the page, is this possible without using a third party plug-in?

If so, does anyone know how you do it?

Thanks again for your help.

Cheers,
Chris [import]uid: 88961 topic_id: 36362 reply_id: 336362[/import]

Hi Chris,
This should be easily possible using just standard display objects (cloud images) that transition from point A to B.

The following tutorial is somewhat similar to what you need, I think… with some necessary modifications of course…
http://mobile.tutsplus.com/tutorials/corona/creating-a-scrolling-background-with-corona-sdk/

Sincerely,
Brent Sorrentino [import]uid: 200026 topic_id: 36362 reply_id: 144447[/import]

Yes, you just need to create a cloud image and periodically move it in your game loop. Each one of my game objects is decorated with an animator list and an animator function. I have animators that move the objects, change their alpha, etc. that are called in the game loop.

Here is the function I attach to each object:

function animate(self)  
 if self.animators then  
 local a = self.animators  
 for i=1,#a do   
 a[i]:update(self)   
 end   
 end  
end  

And here is my HorizontalAnimator, which in my case animates an object between two points on the screen. It’s kind of crude, perhaps, but you get the idea. You could modify it to make your object drift across the screen in one direction (exercise for the reader :-))

local HorizontalAnimator = {}  
HorizontalAnimator.\_\_index = HorizontalAnimator  
  
function HorizontalAnimator:new(min, max, inc, period)  
 local this = {}  
 setmetatable(this, HorizontalAnimator)  
  
 this.period = period  
 this.lastupdate = system.getTimer()  
 this.min = min  
 this.max = max  
 this.inc = inc  
 this.increasing = true  
  
 return this  
end  
  
function HorizontalAnimator:update(object)  
 local tm = system.getTimer()  
  
 if tm - self.lastupdate \> self.period then  
 if object.x \<= self.min then  
 object.x = self.min  
 self.increasing = true  
 elseif object.x \>= self.max then  
 object.x = self.max  
 self.increasing = false  
 end  
  
 if self.increasing then  
 object.x = object.x + self.inc  
 else  
 object.x = object.x - self.inc  
 end  
  
 self.lastupdate = tm  
 end  
end  
  
return HorizontalAnimator  

Attach it to your object like this:

 local a = HorizontalAnimator:new(myObject.x-50, myObject.x+50, 1, 200)  
 myObject.animators[#myObject.animators + 1] = a  

Finally, in my game loop, I call this:

for i=group.numChildren, 1, -1 do  
 local g = group[i]  
 if g and g.animate then  
 g:animate()  
 end  
end  

Note that you can apply multiple affects to a single object (movement, color change, alpha change, scale change, etc.) by adding each animator to the object, like I did the HorizontalAnimator above.

Hope this helps. [import]uid: 58455 topic_id: 36362 reply_id: 144448[/import]

Hi Chris,
This should be easily possible using just standard display objects (cloud images) that transition from point A to B.

The following tutorial is somewhat similar to what you need, I think… with some necessary modifications of course…
http://mobile.tutsplus.com/tutorials/corona/creating-a-scrolling-background-with-corona-sdk/

Sincerely,
Brent Sorrentino [import]uid: 200026 topic_id: 36362 reply_id: 144447[/import]

Yes, you just need to create a cloud image and periodically move it in your game loop. Each one of my game objects is decorated with an animator list and an animator function. I have animators that move the objects, change their alpha, etc. that are called in the game loop.

Here is the function I attach to each object:

function animate(self)  
 if self.animators then  
 local a = self.animators  
 for i=1,#a do   
 a[i]:update(self)   
 end   
 end  
end  

And here is my HorizontalAnimator, which in my case animates an object between two points on the screen. It’s kind of crude, perhaps, but you get the idea. You could modify it to make your object drift across the screen in one direction (exercise for the reader :-))

local HorizontalAnimator = {}  
HorizontalAnimator.\_\_index = HorizontalAnimator  
  
function HorizontalAnimator:new(min, max, inc, period)  
 local this = {}  
 setmetatable(this, HorizontalAnimator)  
  
 this.period = period  
 this.lastupdate = system.getTimer()  
 this.min = min  
 this.max = max  
 this.inc = inc  
 this.increasing = true  
  
 return this  
end  
  
function HorizontalAnimator:update(object)  
 local tm = system.getTimer()  
  
 if tm - self.lastupdate \> self.period then  
 if object.x \<= self.min then  
 object.x = self.min  
 self.increasing = true  
 elseif object.x \>= self.max then  
 object.x = self.max  
 self.increasing = false  
 end  
  
 if self.increasing then  
 object.x = object.x + self.inc  
 else  
 object.x = object.x - self.inc  
 end  
  
 self.lastupdate = tm  
 end  
end  
  
return HorizontalAnimator  

Attach it to your object like this:

 local a = HorizontalAnimator:new(myObject.x-50, myObject.x+50, 1, 200)  
 myObject.animators[#myObject.animators + 1] = a  

Finally, in my game loop, I call this:

for i=group.numChildren, 1, -1 do  
 local g = group[i]  
 if g and g.animate then  
 g:animate()  
 end  
end  

Note that you can apply multiple affects to a single object (movement, color change, alpha change, scale change, etc.) by adding each animator to the object, like I did the HorizontalAnimator above.

Hope this helps. [import]uid: 58455 topic_id: 36362 reply_id: 144448[/import]

Hi Chris,
This should be easily possible using just standard display objects (cloud images) that transition from point A to B.

The following tutorial is somewhat similar to what you need, I think… with some necessary modifications of course…
http://mobile.tutsplus.com/tutorials/corona/creating-a-scrolling-background-with-corona-sdk/

Sincerely,
Brent Sorrentino [import]uid: 200026 topic_id: 36362 reply_id: 144447[/import]

Yes, you just need to create a cloud image and periodically move it in your game loop. Each one of my game objects is decorated with an animator list and an animator function. I have animators that move the objects, change their alpha, etc. that are called in the game loop.

Here is the function I attach to each object:

function animate(self)  
 if self.animators then  
 local a = self.animators  
 for i=1,#a do   
 a[i]:update(self)   
 end   
 end  
end  

And here is my HorizontalAnimator, which in my case animates an object between two points on the screen. It’s kind of crude, perhaps, but you get the idea. You could modify it to make your object drift across the screen in one direction (exercise for the reader :-))

local HorizontalAnimator = {}  
HorizontalAnimator.\_\_index = HorizontalAnimator  
  
function HorizontalAnimator:new(min, max, inc, period)  
 local this = {}  
 setmetatable(this, HorizontalAnimator)  
  
 this.period = period  
 this.lastupdate = system.getTimer()  
 this.min = min  
 this.max = max  
 this.inc = inc  
 this.increasing = true  
  
 return this  
end  
  
function HorizontalAnimator:update(object)  
 local tm = system.getTimer()  
  
 if tm - self.lastupdate \> self.period then  
 if object.x \<= self.min then  
 object.x = self.min  
 self.increasing = true  
 elseif object.x \>= self.max then  
 object.x = self.max  
 self.increasing = false  
 end  
  
 if self.increasing then  
 object.x = object.x + self.inc  
 else  
 object.x = object.x - self.inc  
 end  
  
 self.lastupdate = tm  
 end  
end  
  
return HorizontalAnimator  

Attach it to your object like this:

 local a = HorizontalAnimator:new(myObject.x-50, myObject.x+50, 1, 200)  
 myObject.animators[#myObject.animators + 1] = a  

Finally, in my game loop, I call this:

for i=group.numChildren, 1, -1 do  
 local g = group[i]  
 if g and g.animate then  
 g:animate()  
 end  
end  

Note that you can apply multiple affects to a single object (movement, color change, alpha change, scale change, etc.) by adding each animator to the object, like I did the HorizontalAnimator above.

Hope this helps. [import]uid: 58455 topic_id: 36362 reply_id: 144448[/import]

Hi Chris,
This should be easily possible using just standard display objects (cloud images) that transition from point A to B.

The following tutorial is somewhat similar to what you need, I think… with some necessary modifications of course…
http://mobile.tutsplus.com/tutorials/corona/creating-a-scrolling-background-with-corona-sdk/

Sincerely,
Brent Sorrentino [import]uid: 200026 topic_id: 36362 reply_id: 144447[/import]

Yes, you just need to create a cloud image and periodically move it in your game loop. Each one of my game objects is decorated with an animator list and an animator function. I have animators that move the objects, change their alpha, etc. that are called in the game loop.

Here is the function I attach to each object:

function animate(self)  
 if self.animators then  
 local a = self.animators  
 for i=1,#a do   
 a[i]:update(self)   
 end   
 end  
end  

And here is my HorizontalAnimator, which in my case animates an object between two points on the screen. It’s kind of crude, perhaps, but you get the idea. You could modify it to make your object drift across the screen in one direction (exercise for the reader :-))

local HorizontalAnimator = {}  
HorizontalAnimator.\_\_index = HorizontalAnimator  
  
function HorizontalAnimator:new(min, max, inc, period)  
 local this = {}  
 setmetatable(this, HorizontalAnimator)  
  
 this.period = period  
 this.lastupdate = system.getTimer()  
 this.min = min  
 this.max = max  
 this.inc = inc  
 this.increasing = true  
  
 return this  
end  
  
function HorizontalAnimator:update(object)  
 local tm = system.getTimer()  
  
 if tm - self.lastupdate \> self.period then  
 if object.x \<= self.min then  
 object.x = self.min  
 self.increasing = true  
 elseif object.x \>= self.max then  
 object.x = self.max  
 self.increasing = false  
 end  
  
 if self.increasing then  
 object.x = object.x + self.inc  
 else  
 object.x = object.x - self.inc  
 end  
  
 self.lastupdate = tm  
 end  
end  
  
return HorizontalAnimator  

Attach it to your object like this:

 local a = HorizontalAnimator:new(myObject.x-50, myObject.x+50, 1, 200)  
 myObject.animators[#myObject.animators + 1] = a  

Finally, in my game loop, I call this:

for i=group.numChildren, 1, -1 do  
 local g = group[i]  
 if g and g.animate then  
 g:animate()  
 end  
end  

Note that you can apply multiple affects to a single object (movement, color change, alpha change, scale change, etc.) by adding each animator to the object, like I did the HorizontalAnimator above.

Hope this helps. [import]uid: 58455 topic_id: 36362 reply_id: 144448[/import]