Clickteam Fusion 2.5

Clickteam Fusion 2.5

Not enough ratings
A Guide to Creating Objects in Fusion 2.5
By DannyUK2k14
Welcome to this guide on creating objects at runtime in Fusion 2.5. There are initially two ways you can create objects at runtime (when game is in play) and that is either statically or dynamically. You can manually create the object in a static fashion and give it a preset position in the frame or you can create objects dynamically by referencing their 'actual' name. We will cover BOTH topics in this guide.
   
Award
Favorite
Favorited
Unfavorite
Defining the Difference
In Fusion 2.5 there are now two ways to create objects at runtime. Let's first, define the difference between 'design-time' and 'runtime'. Design-time is in reference to when you are editing your game IN Fusion 2.5. Runtime means when the game is actually running (not designing).

So, when we refer to 'runtime' it means, the game is already running therefore you are not editing the game or any levels. Sometimes it is handy to create objects mid-game and in this guide we will teach you how to do that in two ways. Statically and Dynamically.

Statically means you create the object, you choose the object and you set it's position.

Dynamically means everything above, except you are using a variable name to create the object.

A quick example just to explain this a bit further is, say you have 5 objects, named Object 1, Object 2, Object 3, Object 4, Object 5. You may want the USER to choose which object to create. If you had to do this statically, you would have to create an event for each object like so:

User Clicks on Button + List = “Object 1”
Create Object 1

User Clicks on Button + List = “Object 2”
Create Object 2

User Clicks on Button + List = “Object 3”
Create Object 3


Whereas if you create the object dynamically, you can reference the object name directly and variably like so:

User Clicks on Button
Create “Object”+Str$(number)


So we've gone from 5 events, down to just 1. Seem a little confusing? We will clear that up in the proceeding pages of this guide.
Creating objects in a Static Fashion
So, in this example we will create objects at runtime in a static manner. This is very easy to do. Let's start a new application File > New. Let's jump into Frame 1. We need to create some objects that we will use to create at runtime.



Insert > New Object and insert a new Active Object.



Once inserted onto the playarea, double-click the active to edit it. Let's give it some colour.



Select the paint bucket, choose a colour (like Blue) and set the Tolerance level to 100. Now paint the diamond blue. Click Ok. Now, let's setup the object properties.

Select the object in the frame and hover over to the property window. Click on the 4th tab (runtime options) and uncheck Create at Start (as we want to create it at runtime).



Now, click on the end tab (7th) and you will see the object is called 'Active'. Let's rename it to 'Object 1'.



Once you've done this, right-click on the object and select CLONE and clone the object 3 times. Once you have cloned the object 3 times, Fusion will automatically increment the object name (ie: Object 2, Object 3) for you. Edit these objects and paint them a different colour (just so we know the difference when we create them). That's our playarea setup, now let's jump into the event editor and make some magic happen.



In the event editor we need to detect a keypress (on the keyboard) to create an object and give it a random position on the screen. So let's create our first condition. (For Dynamic Creation, now jump to Step 3.)

Insert a new condition, right-click on Keyboard & Mouse object and select The Keyboard > Upon Pressing a Key.



When you get the dialog prompt, press the Number 1 on your keyboard. When this condition has been inserted, hover over to the 'Create' icon object, right-click and select Create Object...



On the dialog prompt, select the blue diamond “Object 1”. Click OK and in the next prompt click OK again. Now, in the same condition line, hover over to the blue diamond object, right-click and select Position > Set X Co-ordinate. When the expression editor pops up type in “Xmouse” and click OK. Repeat this step to set the Y Co-ordinate, set that to “Ymouse”. This means when we now press 1 on our keyboard, it will create Object 1 and position it where our Mouse is currently positioned (so make sure your mouse is over the frame area). Hit F8 and give this a try.

To create objects 2 and 3, repeat this exact page using 2 & 3 on keyboard, creating the object and setting its position to the Xmouse and Ymouse.

This concludes how to create an object at runtime with a 'set position'. 3 objects with 3 events.
Creating Objects in a Dynamic Fashion
To create objects in a 'dynamic' fashion, please repeat the above steps until you get to this point:

(For Dynamic Creation, now jump to Step 3.)

Now, what we will do here is, track the number of the keypress and then create the object. We will then reset the stored value after the object creation (so we don't get repeated creations). You will see in this section, how you can create 1,2,3,10,100,1000,100,000 different objects in your game with just one condition, instead of 1,2,3,10 etc. conditions. It saves on time, workload and of course events.

Return to the frame editor.

Insert > New Object and insert the “Keyboard Object”. Drop it anywhere in or out of the frame, it doesn't matter.



Now, select all your diamonds and in the properties window, select the Movement Tab (3rd tab) and select “Bouncing Ball Movement” from the dropdown list. This is so we can see our objects moving after we create them later on.

Now let's jump back into the event editor.



So we're good to go. Here is where the magic really happens. In just ONE single event, we can create an unlimited amount of objects without having to write an event for each one.

Insert a new condition, right-click on the Keyboard Object and select
“Upon Key Down”. Like so...



Once you click this it will ask you for the key value. So, we want to find out what key was pressed on the keyboard (ie: 1,2,3,4,5 etc.). So we right-click on the Keyboard Object in the expression editor and select Last Key Pressed.



Click OK. We have our condition created.

Now, hover over to the Create Object icon, right-click and select
“Create Object By Name”.



When the expression editor pops up, we are going to use the last key pressed to create this object by using it's 'last key pressed' value. Remember, we labelled our objects “Object 1, Object 2, Object 3” so we need to say “Object “+Str$(LastKeyPressed). The word “Object “ is a string, however the keypress is a Number, so we convert the Value to a string. So 1 becomes “1” and 2 becomes “2” and so-on.

So right-click, Create Object by name and in the expression editor type in the string “Object “ +(don't forget the space after Object).



Then we need to get the String of the last button pressed. So next right-click on the keyboard object again and select “Key String”, it will then ask for some additional parameters (>Key Value<), so delete >Key Value<, right-click on the keyboard object once more and select “Last Key Pressed”. Your expression editor should now look like



Press Ok.

That's it. How magic was that? One event and we can now create an object by just referencing it's NAME by using the keyboard as a variable. Go ahead and hit F8 and test it.