How do I place different objects on top of each other?

  • Hi Everyone!

    I'm trying to make a game where the player builds towers by putting different sorts of objects on top of each other.

    I am able to create multiple objects on top of each other as long as the object is the same, but when I change the type of object to place, things go weird.

    Let me explain with an example:

    This is a project where I create objects on button click:

    With this code:

    In that project, I have another button to change the type of square to place next. So when I click the button place orange boxes if the type is 0, place green boxes if the type is 1. (green boxes have different size than orange boxes btw). This is what I'm trying to create but I am failing miserably:

    Instead of this, I get green boxes created irrespective of other blocks' positions. I tried couple of things but then decided to stop trying not to complicate things, you can download the sample file here:

    https://www.dropbox.com/s/quv57p9pofrkpe0/blockTowerTest.c3p?dl=0

    Thank you in advance!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • cemdemo

    there is a wide variety of ways to do it... I would probably make a family if you are going to have lots of different block types.

    either you have to keep track of the last Y value, or pick the block with the lowest Y value (since you are building up and higher Y values are lower down the screen).

    I added a variable to keep the last Y. If you are going to be removing blocks and having them drop back down the tower, then you should go with the family idea and pick the block with the lowest Y - since it could change based on what the player is doing.

    https://www.rieperts.com/games/forum/blocktest.c3p

    edit: I was going to say I didn't think using block(-1) would pick the last instance, but I tested it out and it does! I don't remember seeing that in the documentation anywhere. that is very useful!

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