No worries at all.
I’m putting together a very basic example for this use case.
@moon I just updated the basic example if you want to check out how entities work.
https://github.com/selimanac/defold-astar-tilemap-example
That’s awesome. After reading your previous response and revisiting the entity-related documentation I figured it out, but this would’ve made the process way smoother, lol. Thanks for the extension and keep up the good work!
New version v1.2.0
Now supports multi-maps thanks to Alexander Zinov (I don’t know his forum id, sorry)
- Introduces new functions for setting up multi-maps:
astar.new_map_id(),astar.delete_map() - Relevant functions now accept
map_idas an optional parameter - Lua annotations have been added
- Minor code refactoring
Hey,
Thank you for the great extension ![]()
I’m trying to generate a map for astar from a tilemap, similar to how it’s done here:
The difference is I have a big tilesource with many different tiles that could be obstacles or not.
I think I could know whether a tile index corresponds to an obstacle because the tile source has collision groups.
If the tile belongs to the
obstacle or the water-limit group, then it is not passable for the a-star algorithm.
The code would look like this
local x, y, map_width, map_height = tilemap.get_bounds("/map#map")
local tile = 0
local map = {}
for y = 1, map_height do
for x = 1, map_width do
tile = tilemap.get_tile("/test_tilemap#test", hash("layer"), x, y)
--- THE LOGIC I'M STRUGGLING WITH
[if tile is in collision-group water-limit or obstacle] then
table.insert(map, 0)
else
table.insert(map, 1)
end
table.insert(map, tile)
end
end
-- Only tile = 1 passable
local costs = {
[1] = {
1.0, -- E
1.0, -- N
...
}
}
I’m not sure how to get the info of whether a tile index belongs to a specific collision group, any recommendation on how to do this ?
Also sorry if it’s not a question about astar per se. Let me know if I should ask elsewhere.
No worries, but this is indeed not related to this library. If you ask it as a new question, you should be able to get an answer sooner.
As far as I know, it’s not possible. But don’t take my answer as absolute, I haven’t used the built-in physics for a very long time.
You may want to separate the tilemap layer as obstacles and place those tiles there.
Then you can:
tile = tilemap.get_tile("/test_tilemap#test", hash("layer"), x, y) -- passable tiles
--- Add those to map as 1
obstacle_tile = tilemap.get_tile("/test_tilemap#test", hash("obstacles"), x, y) -- OR using https://defold.com/ref/stable/tilemap-lua/#tilemap.get_tiles:url-layer
--- Add those to map as 0
Version 1.2.2 1.2.3 pre-release is now available. It doesn’t include any breaking changes, mostly stability improvements.
If you are using this extension in a production environment, it is strongly recommended that you test this pre-release version. If you run into any issues, feel free to open an issue on GitHub.
my project works fine without adding the a-star dependency.
Once I add “https://github.com/selimanac/defold-astar/archive/master.zip” to the dependency list and re-build or clean build the project (without using any features) i get the following…
INFO:ENGINE: Engine service started on port 64934
INFO:GRAPHICS: Installed graphics device ‘ADAPTER_FAMILY_OPENGL’
INFO:ENGINE: Defold Engine 1.12.3 (0ad9c86)
INFO:PROFILER: Initialized Remotery (ws://127.0.0.1:17815/rmt)
INFO:ENGINE: Loading data from: build/default
INFO:CRASH: Successfully wrote Crashdump to file: C:/Users/andrew/AppData/Roaming/Defold/_crash
ERROR:CRASH: CALL STACK:
ERROR:CRASH: 0 0x7FF75532E5D0 dmCrash::GenerateCallstack D:\a\defold\defold\engine\crash\src\backtrace_win32.cpp:143
ERROR:CRASH: 1 0x7FF75532EC70 dmCrash::SignalHandler D:\a\defold\defold\engine\crash\src\backtrace_win32.cpp:294
ERROR:CRASH: 2 0x7FF75569A688 _seh_filter_exe /tmp/job17437901161034656149/minkernel/crts/ucrt/src/appcrt/misc/exception_filter.cpp:219
ERROR:CRASH: 3 0x7FF7556FA678 __scrt_common_main_seh'::1’::filt$0 D:\a_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:304
ERROR:CRASH: 4 0x7FF7556578F0 __C_specific_handler D:\a_work\1\s\src\vctools\crt\vcruntime\src\eh\riscchandler.cpp:389
ERROR:CRASH: 5 0x7FFB1B7F5350 __chkstk :0
ERROR:CRASH: 6 0x7FFB1B76DDF0 RtlFindCharInUnicodeString :0
ERROR:CRASH: 7 0x7FFB1B7F4450 KiUserExceptionDispatcher :0
ERROR:CRASH: 8 0x7FF7556F94A0 strlen /tmp/job17437901161034656149/minkernel/crts/ucrt/src/appcrt/string/amd64/strlen.asm:64
ERROR:CRASH: 9 0x7FF755324390 lua_setfield :0
ERROR:CRASH: 10 0x7FF755329FE0 luaL_openlib :0
ERROR:CRASH: 11 0x7FF7551F12B0 InitializeAstar /tmp/job17437901161034656149/upload/astar/src/astar.cpp:653
ERROR:CRASH: 12 0x7FF75532CE60 dmExtension::Initialize D:\a\defold\defold\engine\extension\src\extension.cpp:303
ERROR:CRASH: 13 0x7FF75539BF60 dmEngine::Init D:\a\defold\defold\engine\engine\src\engine.cpp:1224
ERROR:CRASH: 14 0x7FF75539ACB0 dmEngineCreate D:\a\defold\defold\engine\engine\src\engine.cpp:2587
ERROR:CRASH: 15 0x7FF7553A1D30 dmEngine::RunLoop D:\a\defold\defold\engine\engine\src\engine_loop.cpp:71
ERROR:CRASH: 16 0x7FF75527E1B0 engine_main D:\a\defold\defold\engine\engine\src\engine_main.cpp:153
ERROR:CRASH: 17 0x7FF755657494 __scrt_common_main_seh D:\a_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
ERROR:CRASH: 18 0x7FFB1A942580 BaseThreadInitThunk :0
ERROR:CRASH: 19 0x7FFB1B7AAF10 RtlUserThreadStart :0
ERROR:CRASH:
I have tried downloading and running the hex-sample and that generates the same result.
My bad, sorry. Fixing it right now.
Edit: fixed
that solved it. many thanks.
Thank you for reporting
Version v1.2.3 is now available.
I strongly advise anyone using this extension to update to version 1.2.3.
What’s Changed
- Fix Defold re-init crash by @Pkeod in Fix Defold re-init crash by subsoap · Pull Request #15 · selimanac/defold-astar · GitHub
- Fixed Lua stack imbalance
- Added guards so map_width, map_height, allocate, and typical_adjacent cannot be 0. They will now return an error instead.
- Costs were not properly freed on Clear().
- Fixed an issue in set_entities that could cause a memory leak if called multiple times.
- Fix: doesn't build on defold 1.12.3 · Issue #17 · selimanac/defold-astar · GitHub


