Test which specific tile of tilemap is in LOS,array question

Get help using Construct 2

Post » Wed Apr 06, 2016 7:31 pm

Hi. As the title says, is it possible to test which specific tiles in a tile map are in LOS, and get their poistion or ID?

Also, i have a question about arrays. I have a very large one, and i would like to specify as condition "for each xy" starting and ending in an specify position. I think ican do an event of "for each XY" and test if that XY is between the values that i specify in another condition, but , wouldn't that test all the XY of the array and have poor performance?

Thanks for your help.
B
7
S
2
G
1
Posts: 17
Reputation: 534

Post » Wed Apr 06, 2016 9:45 pm

There are a few ways to do this. Any LOS check will use collisions. You can use a raycast/LOS function to see if your LOS hits a solid part of your tilemap or not, and get the layout x/y position and use that to get tile index position and ID. This will only allow you two classes of specific tiles though - solid or not solid.

A workaround is to layer some invisible tilemaps and paint solids where you want them to collide, then you can differentiate which tilemap you are hitting to do different actions.

A third way is to draw invisible placeholder sprites with LOS behaviors. This way is probably the simplest if you don't have very complex shapes or very large maps for collisions, as you won't need a custom LOS function.

For your array question, if you don't want to check every cell, use a nested System "For" loop.

Conditions
For "x" from a to b
--- For "y" from a to b

Expression
Array.At(loopindex("x"),loopindex("y"))

Edit: As for performance impact, I'm actually not sure if there is any different between this and for each x/y with additional conditions such as x>a and y<b or something like that. It is something you can test pretty quickly - if there is a noticeable difference let us know! If you can't tell if there is a difference, don't worry about it.
Mistakes were made.
B
53
S
27
G
114
Posts: 1,695
Reputation: 64,438

Post » Wed Apr 06, 2016 10:17 pm

oosyrag wrote:There are a few ways to do this. Any LOS check will use collisions. You can use a raycast/LOS function to see if your LOS hits a solid part of your tilemap or not, and get the layout x/y position and use that to get tile index position and ID. This will only allow you two classes of specific tiles though - solid or not solid.

A workaround is to layer some invisible tilemaps and paint solids where you want them to collide, then you can differentiate which tilemap you are hitting to do different actions.

A third way is to draw invisible placeholder sprites with LOS behaviors. This way is probably the simplest if you don't have very complex shapes or very large maps for collisions, as you won't need a custom LOS function.

For your array question, if you don't want to check every cell, use a nested System "For" loop.

Conditions
For "x" from a to b
--- For "y" from a to b

Expression
Array.At(loopindex("x"),loopindex("y"))

Edit: As for performance impact, I'm actually not sure if there is any different between this and for each x/y with additional conditions such as x>a and y<b or something like that. It is something you can test pretty quickly - if there is a noticeable difference let us know! If you can't tell if there is a difference, don't worry about it.


Thanks a lot for your comment. I'm interested in doing it with just one tilemap that is solid. So, that "raycast/LOS function" you talk about is not the one that is implemented in behavior? I guess i can do it by myself, but it would save me some time if it was possible with the one implemented in construct 2.
B
7
S
2
G
1
Posts: 17
Reputation: 534

Post » Wed Apr 06, 2016 10:24 pm

When using the LOS behavior, it applies to the whole object, as in any part of the object - in this case your entire tilemap. I assume that isn't what you are going for.
Edit/Disclaimer: I'm actually not 100% certain about this, I haven't actually tried it myself.

Here is one excellent raycast function by squiddster, although it might be a little complicated - https://www.scirra.com/tutorials/902/li ... raycasting

Here is another simpler one by R0J0hound - https://dl.dropboxusercontent.com/u/542 ... laser.capx

Edit: fixed the link
Last edited by oosyrag on Wed Apr 06, 2016 11:52 pm, edited 1 time in total.
Mistakes were made.
B
53
S
27
G
114
Posts: 1,695
Reputation: 64,438

Post » Wed Apr 06, 2016 11:40 pm

Thanks a lot, that was what i was looking for!
B
7
S
2
G
1
Posts: 17
Reputation: 534


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 5 guests