How to Create Clouds in a Game?
MegapixelIdeas
Member, PRO Posts: 476
I would like to put clouds in my game that slowly drift across the screen in the background. How would I do this?
Comments
Just create a actor with the height and width of your cloud image.
Then just put a move behavior in there and set it kind of slow, you want it to move slowly rather then very quick.
I would create an actor Cloud and put a behaviuor that change self.motion.x to xspeed to make it go right or -xspeed to make it go left. For example you want the cloud to go from right to left: put change attribute self.motion.x to -1*100. Then you have to add a rule that check:
if self.position.x<= -1*(self.width/2)
then change self.position.x to scene size x +(self.width/2)
With this rule when the cloud reaches the left part of the screen plus its width, it returns to the right part of the screen plus its width. I put plus its width because x position refers the center of the cloud and instead you need the cloud to completely go out of the scene before reusing it.
This way you recycle your cloud without destroy or spawning anything. And this improve performance a lot! You can put more than one cloud for each scene and add some transparency and random attributes so that it will look less repetitive.
For example each time the cloud reach the edge of the screen, you can vary its y position. I invite you to try playing a while with these attributes and see the results.
Hope it helps!
Typed all from my iPod!
Cerulean Swan Games