0 Favourites

How do I fill a rectangle with squares

  • I intend to do a visual counter. I need to fill a big rectangle with little squares each time the player earns points, in the same amount, and destroy this squares too, each time the player lost points, in the same amount. If the player completes all the large rectangle, the game ends.

  • Hi,

    If you use the tilemap, there is a really easy trick:

    Use the Set tile range thing :

    "Set tile range

    As with Set tile, but sets a rectangular area of tiles in the tilemap."

    If you set a range to -1, it will delete the tile.

    If they are separate Sprites, draw your box with a sprite or a tiled background and use an collision is overlapping so the ones that are overlapping get deleted.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Do you have a particular order you'd like the blocks to be added or removed?

    One brute force way would be to add all the square in the editor and give them an instance variable that you set to the value. Then

    Global number health= 100

    Every tick

    --- square: make invisible

    Square: var <= health

    --- square: make visible

    You could also place all the blocks with events.

    For "x" from 0 to 9

    For "y" from 0 to 4

    --- create square at ( 100+16*loopindex("x"), 150+16*loopindex("y") )

    --- square: set var to loopindex("y")*10+loopindex("x")+1

    Where 16 is the size of the squares and 100 and 150 are the top left corner coordinates.

    The way you set "var" controls the order they appear. Above it adds then a row at a time.

    To make it ordered like your pic you could try this to set var.

    For each square ordered by 1000*(X+y)+y descending

    --- set var to loopindex

  • Thanks for the suggestions, guys.

    R0J0hound

    I want the squares to appear from the right to the left.

    I believe that put the squares with a loop is better than create all in the beginning. So, do I've to make all the squares invisible after create them?

    I didn't understand how to associate these squares to the points and show/destroy the same amount of points according if the player wins or loses it.

    Thanks in advance.

  • The idea is just to create them all and hide them as needed.

    The for loop to create the squares can be done once in a start of layout event. The for each ordered can be done once right after all the squares are created to define the order they get shown. You can then do the hiding with the first two events in my previous post. "Health" was the example variable that the squares represent.

  • R0J0hound

    I need to do the opposite: create invisible squares and make them visible each time the player make the points and in the same amount (and invisible again when he/she loses the points - in the same amount and in the same order). I decided to create an example with your suggestions to see if I understood the implementation. However, I didn't understand the expression that controls the order of the squares. I included some text fields for testing: one to check the order of the square and another one to simulate the points. I'm really grateful for your help.

  • (R216)

  • Thanks for your time, RamPackWobble

    I'll try to implement it.

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