Question about instances and some tips

0 favourites
  • 5 posts
From the Asset Store
Logo Quiz with 150 prepared logos and answers, automatic question and answer mixing
  • Hi everyone, I recently joined the Construct family and I'm quite new to coding and gamedev, but super motivated. I'm currently trying to hone my skills by trying to recreate the logic of the mobile game Ball Blast. I have two questions and was hoping someone from the community could help me:

    1. In my code I have the following:

    The first part of the code works fine, but the the three last lines that make the balls shake every time a bullet hits only work when there's one instance of a ball live on the screen. If there are two or more, it stops working. The damage and health display work perfectly fine. I tried a lot of different ways but can't seem to make it work.

    2. Do you have any tips regarding how to store the value of the initial health for each ball? For example, the first ball spawns with 20 health, then when it's destroyed it splits into 2 different balls, each with half the previous health value (two medium balls with 10 health) and so on.

    Currently, I store the health of my test instance in a static group variable called patentHealth, then when the health is less than 1, I spawn two balls at the destroyed position and assign parentHealth / 2 to each ball, and so on until the smallest ball is destroyed. It works for testing purpose, but when there will be many instances of the balls this isn't going to work. Should I use arrays?

    I hope my explanations are clear, I'm not used to ask gamedev/coding question so please let me know if you need more info. Thank you!

  • 1. Use "On collision" event instead of "Is overlapping".

    "Is overlapping" will continue to fire every tick, about 60 times per second, while the objects are overlapping. "On Collision" is a trigger, it will happen only once at the moment two objects touch. I'm guessing this is what you want?

    And remove "Trigger once"! This condition can cause a lot of damage when not used correctly, I suggest forgetting about it until you have a good understanding of how events in Construct work. And never use "trigger once" with objects that have multiple instances.

    2. Use instance variable on the Ball sprite. Then each ball instance will have its own health.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi dop2000, thanks a lot for your reply.

    1. I will remember to avoid trigger once from now on, thanks for the tip. I thought it was safe to use it as a sub-event while the main event was true. Anyways, I switched to on collision and set it as follows but the issue remains exactly the same, the last three lines of code that create a short shake effect on the Ball only work when there's one instance of Ball on the screen, but if there are two or more it stops working until all instances are destroyed and only one instance remains:

    2. All my objects already have an instance variable for their health and it works, but what I was asking is about storing the initial value of each instance, sorry it wasn't very clear. I did a little diagram of how I would like it to work:

    Currently since I'm testing, I assign the initial health to a static local variable (set parentHealth to Ball.health) that I can reuse when a new ball spawns. This works now but when there will be multiple instances of the Ball object it will be tricky so I was wondering what would be the best option to store and access this data dynamically.

    Maybe I can share the project if you want to take a look?

  • 1. If the event is triggered and the bullet is destroyed, then the last 3 actions should definitely work with the current instance of the Ball. There may be some other event or behavior which doesn't allow to change object size. As an experiment try changing Ball opacity and increase the wait duration.

    2. When the ball is destroyed, you can copy its health into a local variable. Then spawn two new balls and assign them half of that health from the local variable. I don't see any issues here, I would've done it the same way.

  • 1. Thank you, you were right indeed! I had a set size for the ball objects that was interfering, reworked it and now the shake works perfectly.

    2. Great, I will use that for now and see if I need to make changes later when I'll randomly spawn multiple instances of ball objects of the same size.

    Back to work, have a great day dop2000

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