How do I erase diagonals on tilemap

Get help using Construct 2

Post » Mon Sep 05, 2016 5:39 am

Hi all

Image
I have this diagonal Sprite Overlapping a tilemap.
I want to erase all tiles the diagonal sprite is overlapping.
How can i do that?

I know how to erase with the tile range, but that only works with a width and height.
Not X&Y to other X&Y. (By the way @Ashley is this not a nice feature to implement?)

Hope someone has the answer.
Thanks!
B
59
S
20
G
14
Posts: 779
Reputation: 13,857

Post » Mon Sep 05, 2016 11:45 am

I found a way (although this is very slow, so i still am looking for a quicker way).
Image
The pink line are all little sprites 32 x 32
They move from left to right and check if overlapping the dark grey sprites.
If so, then the tilemap erases the tile at the position of the pink sprites.

It works, but i rather use a quick method so players don't have to wait as long when a new level is being generated.
B
59
S
20
G
14
Posts: 779
Reputation: 13,857

Post » Tue Sep 06, 2016 6:19 pm

In less then a second.

https://www.dropbox.com/s/rwwyr8yda9j41 ... .capx?dl=0


Or if it has to be exact.

https://www.dropbox.com/s/m8exkwtgeiq2x ... .capx?dl=0


Edit: offset in last one should be 13/-13, my error
B
33
S
18
G
28
Posts: 2,470
Reputation: 20,904

Post » Tue Sep 06, 2016 7:38 pm

Dum da da dum
Trig to the rescue!
Since angle would be a constant you could loop by the tile size with:
int(startx+cos(yourangle)*loopindex*tilesize)
int(starty+sin(yourangle)*loopindex*tilesize)
Of course you would be limited by the angle choice. Not all angles would give a perfect line.
Image ImageImage
B
168
S
50
G
164
Posts: 8,228
Reputation: 105,575

Post » Wed Sep 07, 2016 12:50 pm

@99Instances2Go

Wow that is truly fast, and a easy way to do it!
Thank you for educating me :-)
This is helpful in many cases.
B
59
S
20
G
14
Posts: 779
Reputation: 13,857


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 10 guests