0 Favourites

How do I smash a block after it's hit twice?

  • My Breakout-game is coming along great, and now it's time to smash some blocks. The regular ones are easy enough. On collision with ball, simply play a sound and smash them (in that order, so I'm sure the sound is played.) But the harder blocks?

    What I've done so far is that I have a zero-speed block-animation with two frames (the undamaged and cracked block), then simply change the frame from 1 to 0 when the ball hits (as the animation starts with frame 0.) I do this by first creating a local variable called Smashing when the block is created and set it to 2, then set it to 1 when the ball hits. This works fine. I've tried having three of those solid blocks plus a few normal blocks in a level, and everything works fine. (note: It's tempting to set the frame directly to 1 when the ball hits, but by using a variable, I can have as many frames as I want. I could require a block to be smashed ten times this way, if I wanted to be a bit evil. But I wouldn't do that. Nope. Not at all. Most likely-)

    However, how do I smash the harder blocks the second time they are hit? It should be simple enough to check the variable of the block once it's hit, then destroy it if the variable is set to 1. But... how? Much as I love Construct2, I can't seem to figure out how to make an event have three steps instead of just two. (ball hit -> check variable -> smash it if necessary.) All I can do is check the variable if the ball hits. I simply can't find a "Check variable" anywhere?

  • It sounds like you want to want to compare an instance variable. You do that as an event and not an action. So add an event, and double click the object that has the instance variable that you want to create a condition from. You should then have an option to "compare instance variable".

  • YES! That worked. Much appreciated.

    For reference, if others struggle with the same:

    I first set the variable Smashing to 2 when the block is created. Then when the ball hits the block, I subtract 1 from the variable Smashing.

    Next, I create one event where I Compare the variable, and check if it's set to 1. If it is, I change the animation frame to 1 (to get the cracked block).

    Finally, I check again in a new event, and see if the variable is 0. If it is, destroy the block.

    This way, I can use multiple blocks pr level, as they all use individual variables. Adding more frames (to make the blocks harder) is a bit tricky, as you'll need to check for every single number of the variable, and take actions accordingly.

    Also, I set all of this on a General Stuff-event sheet, then include it on every Level-specific event sheets. This way I only need to create the events for each block once, and I can do fun stuff with each individual level if I want to (like scripting sequences etc.)

  • Another way to do it would be to destroy the brick if it's on the last frame, otherwise move onto the next frame.


  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Interesting, I didn't know that. Thanks, I'll give it a try.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
99 10,139
karshinkoff's avatar
Unread hot topic
64 4,529
nimos100's avatar
Unread hot topic
56 4,734
MPPlantOfficial's avatar