Using Arrays


Attached Files

The following files have been attached to this tutorial:



Download now 198.28 KB


3,388 visits, 4,810 views



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.

Someone asked if he or she can make a slide grid game. Every time new game start grid must change to different tile.

If this person or persons has bothered to search the forum then would have found tutorial done by

Tutorial written by ramones Originally published on 23rd, May 2012 - 10 revisions

I would not have to do this tutorial. Person excuse was, I am sorry but one could not understand. We’ll see if you can understand this tutorial.

Start C2 and new project. Call it whatever you wish.

1. Window size 480 x 480

2. Name the layer background, colour as you like and lock it

3. Add new layer and name it GUI

Insert object Array and name it Positions.

Set width = 9

Height = 1

Depth = 1

Now create nine tiles and name it as sprTX, sprVertical, sprSquare, sprHexo, sprHex, sprCircle, etc

Add mouse. Add button object,

Now we need Instance variables for our sprite so when we click on again button the entire sprite has to change position and we must know which sprite is where. Therefore our Instance variables has meaningful name like:

ID = 0

Grid_pos = 0

sprTX ID = 0

Grid_pos = 0

sprVertical = 1

Grid_pos = 0 and so on your screen looks like this:

Now let’s add some code. Click on events and enter global variables:

You will need 4

Row = 3

Col = 3

X_start = 160

Y_start = 160

Now enter this code below

On startof system

Right Click on above (on startof system) and insert add sub_event and enter code

Now we add four Local Variables

I = 0

J = 0

Temp = 0

Counter = 0

Once this is done we have to enter code for each sprite. Here I will show you only 2 sprite codes. Then explain it how you can copy and paste same code and change the sprite name.

First click sprTX block with mouse and then ctrl+C to copy. Now press ctrl+V this action should paste the sprTX block. Now all you have to do is right click block sprTX andclick on REPLACE OBJECT

This box will open

In this box click on object you want to replace. Your object is replaced. Do this for other sprite code but not for sprCircle.

Now not every code for sprite is same therefore remember our sprCircle, this has entirely different code.

For sprCircle add this code

If you have done correctly your project should work fine, if not then use my capx to find out.

Good luck



Download now 198.28 KB

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