Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Qiso: Check if path between two tiles exists and make tile "walkable"
Started by J@V0 Jun 03 2019 11:08 AM

13 replies to this topic
qiso tile path
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

J@V0

[GLOBAL: userInfoPane.html]
J@V0
  • Enthusiast

  • 80 posts
  • Corona SDK

Hi,

 

Let's start with the simplest question.

In the tileset provided on Qiso's website there are 8 properties called like "disable-path-east". Are those the ones I need to set to False to make the tile walkable?

 

Now comes my problem, I can't find a way to check is two tiles are connected by a path (i.e. connected by a continuous series of tiles which are walkable in any direction). Qiso probably has some non-documented function which can do that. Maybe part of populateRoute() ? In that case, could there be a property called "walkable" or similar, to make this check easier?

 

Edit: My goal is to be able do check if two tiles (building) are connected and if so, add a bonus...

 

Thanks

J@V0



[TOPIC: post.html]
#2

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 463 posts
  • Corona SDK

Those control whether a tile is walkable or not, yes. By default all tiles are assumed to be walkable from all directions so you only really need to toggle them if you want to disable a route.

Ref checking if a tile can be reached from another... That's an interesting request actually. The functionality is in there and used internally yes, but I'm not sure if it's currently exposed for calling. Leave it with me, I'll try to get a function in place tomorrow for you.

[TOPIC: post.html]
#3

J@V0

[GLOBAL: userInfoPane.html]
J@V0
  • Enthusiast

  • 80 posts
  • Corona SDK

Thanks Richard, look forward to the new function!

 

Since most of my tiles will be non-walkable do I need to set all 8 properties to True for all my tiles or is there a simplier way to do?



[TOPIC: post.html]
#4

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 463 posts
  • Corona SDK

Just pushed this live so it might take an hour or so for the Corona build servers to synchronise before you can use it, but here you go!

 

https://qiso.qweb.co.uk/documentation/data/pathfinding/functions/findroute

 

In a nutshell, pass the x,y of a From tile and a To tile and Qiso will either return a table of route data, or false if no route exists.

 

Ref disabling all routes - currently you'd have to set all 8 properties yes, but you can do this in bulk within Tiled. Just select all of the sprites in your sheet and add + tick those 8 properties while all are selected. Then select all of the sprites where you need to re-enable a certain direction and untick that property again. It shouldn't take long to define them all this way.

 

That said, Qiso is optimised more for maps where tiles are mostly walkable... if your world is huge, you might find memory usage increases somewhat. Let me know if this does become a problem.



[TOPIC: post.html]
#5

J@V0

[GLOBAL: userInfoPane.html]
J@V0
  • Enthusiast

  • 80 posts
  • Corona SDK

Does the function check a specific layer? It looks like it.

 

I have my Ground layer with grass which is not walkable and the function returns False as expected. If I add my roads to the building layer (in game or via Tiled), it still returns false (unexpedted!), however if my roads are added to the Ground layer (via Tiled) it returns the table (as expected).

 

Your way of managing the properties works great! Thanks for the tip!



[TOPIC: post.html]
#6

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 463 posts
  • Corona SDK

The layers all work together. If a tile contains 3 layers and one of those layers is a sprite that disables a path, that path should then be disabled for the tile.

I can see how this would be an issue in your case though. Would it be feasible to add the grass to the road sprite and instead of layering them, then just replace the unwalkable grass with a walkable road? Not ideal I know, but it should work.

I'll see if we can implement a toggle though, to reverse the disable-path system into an enable-path system.

[TOPIC: post.html]
#7

J@V0

[GLOBAL: userInfoPane.html]
J@V0
  • Enthusiast

  • 80 posts
  • Corona SDK

well, that would add quite some complexity because I would need to store separately each tileID of the map in case the building is moved/deleted and I would need to revert back to the original tileID (grass, stones, water...). 

So it would be great if you could find a way around that.

 

Let me know.



[TOPIC: post.html]
#8

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 463 posts
  • Corona SDK

Here you go =).

 

https://qiso.qweb.co.uk/documentation/data/pathfinding/functions/pathfindingmode

 

Before your qiso.loadTiledMap() call, set qiso.pathfindingMode(2) to switch to a new disabled-by-default mode, and instead of disabling paths on your tile sprites within Tiled, enable them using new enable-path-* properties ( https://qiso.qweb.co.uk/documentation/data/map-handling/functions/loadtiledmap ). The documentation should have all the details but if you have any questions or issues, let me know.



[TOPIC: post.html]
#9

J@V0

[GLOBAL: userInfoPane.html]
J@V0
  • Enthusiast

  • 80 posts
  • Corona SDK

Thanks Richard I've tested the function and it works fine but in my case how should I proceed?

My grass has no property set so with pathfindingMode(2) it will disable the paths and my roads have the enable-path-* properties. But as you mentioned in your previous message "one of those layers is a sprite that disables a path, that path should then be disabled for the tile".

 

Any suggestion?



[TOPIC: post.html]
#10

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 463 posts
  • Corona SDK

In mode 2, you should be seeing the reverse of that. I.e. if a tile has a road sprite and your roads have the enable-path-* properties set, it should become walkable.

If this isn't working for you, could you fire over your Tiled file + images please and I'll have a play around?

[TOPIC: post.html]
#11

J@V0

[GLOBAL: userInfoPane.html]
J@V0
  • Enthusiast

  • 80 posts
  • Corona SDK

I've checked again and my file seems correct. Please find the images and Tiled file in attachment. 

My test code is the following:

qiso.pathfindingMode(2)
qiso.loadTiledMap("map1")

  local routeData = qiso.findRoute(1, 1, 3, 3)
  if(routeData ~= false) then
    for i = 1, #routeData, 1 do
      print("From " .. routeData[i].xFrom .. "," .. routeData[i].yFrom .. " To " .. routeData[i].xTo .. "," .. routeData[i].yTo )
    end
    else print(routeData)
  end

It prints FALSE in the console.

Attached Files



[TOPIC: post.html]
#12

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 463 posts
  • Corona SDK

Thanks for providing that. Turns out there was a bug, sorry. Your set-up is absolutely correct but mode 2 just wasn't working quite as solidly as we thought.

 

Fixed now but it might take an hour or so for the build servers to update. Once that's happened, your above code should just return a proper path.


  • J@V0 likes this

[TOPIC: post.html]
#13

J@V0

[GLOBAL: userInfoPane.html]
J@V0
  • Enthusiast

  • 80 posts
  • Corona SDK

Works perfectly now. Thanks for the great support, as always  :)



[TOPIC: post.html]
#14

richard11

[GLOBAL: userInfoPane.html]
richard11
  • Contributor

  • 463 posts
  • Corona SDK

Brilliant. Let me know if you stumble into anything else.


[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: qiso, tile, path