Fade Between Random Layers using Indexed Naming Convention

1

Attached Files

The following files have been attached to this tutorial:

.capx

randomlyfadebetweenlayers.capx

Download now 172.7 KB

Stats

1,225 visits, 1,526 views

Tools

Translations

This tutorial hasn't been translated.

License

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.

Published on 2 Aug, 2014. Last updated 19 Feb, 2019

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:

Background0

Background1

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.

.CAPX

randomlyfadebetweenlayers.capx

Download now 172.7 KB
  • 0 Comments

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