Fade Between Random Layers using Indexed Naming Convention

  • 6 favourites

Attached Files

The following files have been attached to this tutorial:



Download now 172.7 KB


1,133 visits, 1,418 views



This tutorial hasn't been translated.


This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

This capx is a simple program that demonstrates fading between 5 different colored background layers each click. Demo

A good practice when naming objects or layers of a similar type is to use an indexed naming convention. This is accomplished by naming the Layers to be used as such:



Background2 etc..

We can then use a numerical variable (in this capx case 'bkgLayer') to reference the layers.

For example, if we want to reference layer "Background2", we set our variable 'bkgLayer' =2, and then can reference the layer:

layer = "Background" & bkgLayer

Once we have the variables to reference our layers, we can trigger a simultaneous fade in/out by gradually adjusting the opacity of the layers. In this capx, new layers displayed are chosen at random, and will also be different each click (the same layer will not be chosen twice in a row).

The capx should be self explanatory. Some of the functionality could be useful for testing different backgrounds in your game, and could easily be applied to other objects (such as sprites or layered menu items). Also, instead of 'random' picking, you could cycle through, or set the fade events to be triggered by specific events.

This is my first tutorial. I just wanted to consolidate a few tips I learned from the wonderful forum community here. I hope you find this useful.



Download now 172.7 KB

  • Order by
Want to leave a comment? Login or Register an account!