FALLING LEAVES

A RM2K3 tutorial on creating falling leaves using sprite events.

  • Jude
  • 07/16/2011 01:18 PM
  • 7548 views
Introduction
This tutorial will step you through creating a falling leaves visual effect through the use of parallel processes, variables, switches, and sprite events. There are methods involving pictures which are simpler, but a sprite event method is independent of map size, can have more complex animation and movement, and has the potential to interact with other objects on the map.

Getting Started
The example images used in this tutorial were taken from a sample project linked below, which has a maximum of twelve simultaneous leaves and uses two parallel processes. While it is (far) easier to include the parallel process in each leaf sprite event, I have condensed them into two separate parallel processes to improve performance. I created a small leaf sprite for use in this project: one is the falling animation and another is the animation for a leaf floating on water.



For this sample project I used thirteen switches and eighteen variables, the purpose of which I will describe below.



Switches 0001-0012 are used to activate an animation and movement state for each of the twelve leaves.

Switch 0013 is used to activate a parallel process that checks the terrain ID on which a leaf lands upon, which is later used to toggle an animation state for a leaf on water.

Variable 0001 is a timer used to randomize the time gap between each leaf animation.

Variables 0002-0004 are used to store the hero's coordinates, which create a reference point for where the leaf animations should begin.

Variables 0005-0016 store the terrain ID upon which each leaf sprite event lands, used to toggle an animation state for a leaf on water.

Variables 0016-0017 are the coordinates for a leaf sprite event, used when grabbing a terrain ID.

Creating the Leaf Sprite Event
First you should create the leaf sprite events. Creating the leaf sprite events first is necessary so that the parallel processes can point to the correct events later. In my example I have included twelve sprite events, but I will only cover the creation of one.

Each leaf sprite event is composed of three pages. The first page is static sprite, which is how a leaf will look when it is motionless on the ground. Set this event to be below the hero, so that it can be stepped over. Also set it to a fixed graphic to improve performance.



The second page is the animation of a leaf sprite that has landed on water. Be sure to use the appropriate terrain ID variable for each sprite event to deconflict with other events. Since I used the RTP resources and default database settings, terrain ID 9 identifies a water tile.



The third page is the actual falling leaf animation. It will be enabled whenever its appropriate switch is active and follows a custom movement pattern. You can set the movement pattern for however you like or follow my sample. However, at the end of the pattern you must turn on the terrain ID check switch (reference s0013:TerrainID Check), followed by turning off the appropriate leaf switch (reference s0001:Leaf01). This will activate the parallel process that checks what type of tile the leaf has landed upon, and then returning the sprite event to either page one or two. You must also check "Ignore Impossible Moves" so that a leaf doesn't get stuck on the map edges, and also "Repeat Pattern" or the leaf will remain inert when it is reactivated later.



Spawning a Falling Leaf Animation
Now you can create the parallel process which will control the spawn rate and spawn location of each leaf animation. I will step you through a single leaf spawn, from which you can copy/paste the rest. For more detail, look inside the sample project at the bottom.

Highlighted in blue are the event functions used to spawn a leaf. Initially, a random timer is set. You can change this depending on the rate of spawn between each leaf you want. When the timer reaches zero, the parallel process will grab the hero's current coordinates. It will then add or subtract a random number from each coordinate to provide a location near the hero where the leaf can spawn. You can use whatever boundaries you'd like, but mine will keep the leaves landing on screen. After this you use the Change Event Location function to move the appropriate leaf sprite event, and then toggle the appropriate switch to activate its movement and animation. Then it sets a new timer and jumps to the next leaf event.



Terrain ID Checking
I have created a second parallel process which, when a leaf finishes its movement pattern, will check to see what type of tile a leaf has landed upon. This is a lot of copy and paste, but highlighted in blue are the event functions used for one leaf. First you grab the coordinates of the appropriate leaf sprite event and store it in a variable. Then use the Store Terrain ID function using the leaf sprite event's coordinates and the appropriate terrain variable. After all sprite event locations have been checked, turn the terrain ID checking switch off to improve performance.



Conclusion
You should now have a functional falling leaf effect using sprite events. Leaves will randomly spawn near the hero's current location and fall to the ground; even changing their animation if landing on water. I am sure there is a way to optimize this, but this method works pretty well. Below is a sample project I used when making this tutorial, which requires the RTP.

Download: Falling Leaves Sample

Posts

Pages: 1
Wow... I was really skeptical at first with the whole "using charsets" for this sort of stuff but the sample was really impressive.
thank you thank you thank you thank you

EDIT -- If anyone's interested I edited Jude's leaves for my own project, maybe I could save someone a bit of trouble? (Mind you you'll have to edit the colors to match the trees you're working with)

This is awesome... The leaves even make small ripples on the water...
Thanks. I drew those leaf animation in MS Paint in like two minutes. You can create similar effects using character events. Like burning embers that bounce off the ground and then smoke. Make it windy by sending the leaves at a hard angle, and mixing in sprite events that loop a 360. Really, whatever you can come up with. All that matters is how you spawn their starting point relative to the hero, their move pattern, and any conditions that change the animation.
Maan, those leaves look amazing, just downloaded the sample project. Very nicely done :>
Thanks for the tutorial, mate :D
I can add some for romantic scenes (/^O^)/
Pages: 1