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

0 favourites
  • 5 posts
From the Asset Store
Soldier Test
$9.99 USD
A Construct version 2 & 3 "Stand-alone" RPG game with "In-Game Module" (IGM) integration.
  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

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

  • 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

  • Thanks a lot, that was what i was looking for!

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