How to achieve the effects of floating flowers and falling leaves in the game

This article was first published on the WeChat public account: Little Ants teach you how to play games. Welcome to pay attention to receive more original tutorial materials for learning to make games, and learn some game development knowledge every day.

Hi! Hello everyone, I am Little Ant.

Today's article shares how to realize the effects of floating flowers and falling leaves in the game, and adding them to the game background can make your game more lifelike.

Before we talked about how to realize a rain in the game, mainly using the randomness, a series of random processing to simulate the effect of rain, also need a variety of random processing for floating flowers and fallen leaves.

I don’t know if you have carefully observed the process of petals falling. When a gust of wind blows, a petal floats away from the flower, and slowly falls, rotates, and turns in the direction the wind blows... If there is Many petals are falling, and each petal has a different trajectory, a different falling speed, and a different flipping method... There are no two identical leaves in the world, and there are no two petals with the same falling trajectory. The world is beautiful because of randomness.

Compared with water droplets, petals are a little more random. In addition to size, transparency, and moving speed, the randomness of wind, petal rotation and flipping should also be increased.

When we come to the WeChat Mini Game Creation Tool, we first prepare the resources.

As shown in the picture, it is all the resources needed, two petals, one fallen leaf, one basic text, and one background.

Next, select a petal sprite, then click the "Manage Behavior" button in the property area to open the Behavior panel, and enable the two behaviors of "Rotate" and "Flip" for it.

We will use these two behaviors to achieve the rotation and flip effects of the petals.

After the behavior is enabled, you will see behaviors related to "Flip" and "Rotate" in the property area. Turn off the default "Auto Start" option, and we will use building blocks in the logic to manually control the start.

Next, create two local variables for the petal, one "X Offset" and one "Y Offset". These two variables record the current wind force on the petal.

Finally, let's take a look at the logic of the building blocks on the petals.

A lot of randomness is used in this building block, including the randomness of petal size, transparency, wind force, flipping time and direction, and rotation time and direction.

Applying this series of randomness to a small petal can produce wonderful effects.

Preview the scene.

此时,应该能够感受到一阵向右的风从一棵樱花树上经过,扰动了树枝,一片片的樱花被吹起,开始了充满随机性的舞蹈。

至于落叶该怎么实现呢?与落花是一样的逻辑,只不过调整一下其中的各种随机数值,一直调整到你觉得对落叶满意时为止。

当春天的樱花碰撞到了秋天的落叶,感觉有点儿怪怪的。

不过,在游戏的世界里没有什么是不可能的。这也是做游戏的一个魅力之处,你是一个游戏世界的创造者,这个游戏世界是什么样子,将完全由你来决定。

最后,我为这个小示例增加了一个“溪流鸟鸣”的背景音效,打开它,看着缓缓飘落的樱花和树叶,听着清澈的溪流和鸟鸣声,分分钟就能够让你的那颗躁动的心安静下来。

Guess you like

Origin blog.csdn.net/flyhorsejun/article/details/128617148