How do I 1 set of code for multiple objects?

From the Asset Store
Be quick and choose the right answer for the shown equation.
  • Hi Everyone,

    In the past I used gamemaker which has a parent/child function that allows you to create 1 set of code for a parent and any children under that parent will execute the code the same for themselves.

    What I'm hoping to be able to do is have a 'build bar' in my game where you click various icons that creates a cursor to build that object (like any type of building game). But what I'm not wanting to do is recreate that code for each and every object that can be built in the game.

    Does something like this currently exist in construct 3?

    Thanks in advance.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Parents/children are known as the Scene Graph in Construct 3 and they allow child objects to transform with certain aspects of the parent object e.g X&Y pos, size, Z-elevation etc.

    Containers allow for the automated picking of objects within a container, meaning you do not have to specify the specific instance of an object you are trying to pick when referencing that object in relation to another within the container.

    But I believe you may be looking for 'families'. You can add many object types to a family and then execute code on the family. Families can also have instance variables that are inherited by the objects within the family. Families is a paid only feature however.

    Elsewise an easy and simple way is to use a single object for your icons and use different animation frames to represent the different buildings.

    You could use something like:

    On Icon clicked:

    if icon is animation frame 1 - create buildingicon at mouse.x,mouse.y & set animation frame to 1

    if icon is animation frame 2 - create buildingicon at mouse.x,mouse.y & set animation frame to 2

    etc.

    Every tick if buildingicon exists - set position to mouse.x,mouse.y

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)