How do I fill a rectangle with squares

Get help using Construct 2

Post » Fri Oct 23, 2015 7:58 pm

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.

Image
B
74
S
13
G
4
Posts: 1,000
Reputation: 8,041

Post » Fri Oct 23, 2015 8:36 pm

Hi,

If you use the tilemap, there is a really easy trick:
https://www.scirra.com/manual/172/tilemap

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.
B
29
S
8
G
4
Posts: 767
Reputation: 5,985

Post » Fri Oct 23, 2015 9:58 pm

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
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Fri Oct 23, 2015 11:18 pm

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.
B
74
S
13
G
4
Posts: 1,000
Reputation: 8,041

Post » Sat Oct 24, 2015 2:09 am

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.
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Sat Oct 24, 2015 11:04 am

@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.

https://www.dropbox.com/s/fp7oyadnngpos ... .capx?dl=0
B
74
S
13
G
4
Posts: 1,000
Reputation: 8,041

Post » Sat Oct 24, 2015 2:58 pm

August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,832

Post » Sat Oct 24, 2015 9:55 pm

Thanks for your time, @RamPackWobble

I'll try to implement it.
B
74
S
13
G
4
Posts: 1,000
Reputation: 8,041


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 14 guests