How do I pick all existing tiles inside a circle ?

Get help using Construct 2

Post » Fri Feb 20, 2015 1:26 pm

Hi !

I don't know if I can be more precise. :D

I have a landscape made from tiles.
I want to remove/change all tiles in a radius of X tiles when I click on a tile.

How to do that ?
B
12
S
7
G
7
Posts: 447
Reputation: 4,270

Post » Fri Feb 20, 2015 1:38 pm

For each tile
distance(tile.x,tile.y,yourcenter.x,yourcenter.y)<radius do stuff
Image Image
B
163
S
48
G
99
Posts: 7,433
Reputation: 71,488

Post » Fri Feb 20, 2015 2:33 pm

I looked for this kind of condition, but I didn't find it :/
B
12
S
7
G
7
Posts: 447
Reputation: 4,270

Post » Fri Feb 20, 2015 2:41 pm

It would depend on what you are doing, or object you are using.
Distance() is a system expression.
On object clicked, for each tile, system compare distance()<radius, do foo.
Tilemaps would be a much different approach.
Image Image
B
163
S
48
G
99
Posts: 7,433
Reputation: 71,488

Post » Fri Feb 20, 2015 2:42 pm

Here's a little example to get you going :)
You do not have the required permissions to view the files attached to this post.
B
19
S
6
G
6
Posts: 1,101
Reputation: 5,646

Post » Fri Feb 20, 2015 3:31 pm

Thank you for your replies :D
I'm not using sprites, but tiles, and I didn't find any "for each tile" condition.

The only way I see is using two "for" loop (one for X coordinate, one for Y coordinate).

Is this the best way to go ?
B
12
S
7
G
7
Posts: 447
Reputation: 4,270

Post » Fri Feb 20, 2015 3:35 pm

Ah, tilemap - yeah, a loop with a check sounds like the way to go.
B
19
S
6
G
6
Posts: 1,101
Reputation: 5,646

Post » Fri Feb 20, 2015 5:10 pm

No such thing as a circle in the tilemap object.
Take a look at the "set tile range" action.
Image Image
B
163
S
48
G
99
Posts: 7,433
Reputation: 71,488

Post » Fri Feb 20, 2015 6:44 pm

I did like this :
tilescircle.png


Works well. I spent about one or two hours to figure out I used positionToTile instead of tileToPosition though. :mrgreen:
By the way if the global variable blockSize is equal to a tile size I could also write :

loopindex("tileX")*blockSize
instead of
map.tileToPosition(loopindex("tileX"))
and so on.

It's a matter of preference but I don't really like to have too much parenthesis nor dots.

I can't use tile range because I'll need to test every tile in this area later to do stuff.
You do not have the required permissions to view the files attached to this post.
B
12
S
7
G
7
Posts: 447
Reputation: 4,270


Return to How do I....?

Who is online

Users browsing this forum: TommyR and 23 guests