Easy Pathfinding in Corona SDK - Free Lib Does All the Work!
course's star rating by considering a number of different factors
such as the number of ratings, the age of ratings, and the
likelihood of fraudulent ratings.
Find online courses made by experts from around the world.
Take your courses with you and learn anywhere, anytime.
Learn and practice real-world skills and achieve your goals.
There are tons of games where objects need to get from Point A to Point B, all the while avoiding dead ends, cliffs, and who knows what all.
That's where pathfinding comes in.
The Jumper library is available free on Github and this mini-tutorial includes videos with 4 sample demos that will get you up and running fast!
You can pound it out yourself, or get a headstart for less than the price of a movie and snacks!
Note! This is NOT a course for beginners. There is less "hand-holding" in this mini-tutorial than in most of my courses. ;)
Not for you? No problem.
30 day money back guarantee.
Learn on the go.
Desktop, iOS and Android.
Certificate of completion.
|Section 1: Pathfinding with Jumper|
In the Introduction post I gave you a link to Jumper on GitHub, but for this tutorial I’m going to use the version I just downloaded — that’s so that if something changes, the demo program will still work.
But if you’re going to publish a game using Jumper, it’s probably a good idea to use the latest version. Just do some testing first to make sure it’s working the same as the old version.
Also, there are doc files and other examples in the Jumper-master that you’ll download, so it’s a good idea to grab it. In the demo program we’ll just be using a part of the whole download (the folder called jumper).
Here’s where to grab the whole thing:
If you’re a git pro, clone that — for the rest of us, just use the ZIP button on that page to download the latest copy.
Note! Just received an email from Roland Yonaba, author of Jumper, and he said this:
I always advise people not to grab the latest commit of the librarybecause it might be a cutting edge development version and full of bugs. Instead, just grab the latest release (see https://github.com/Yonaba/Jumper/releases). The link to the latest version is always featured on the README (https://github.com/Yonaba/Jumper#download-latest).
Download the sample code from the right, unzip, and pull into Outlaw (if you’re using that IDE – it’s not required).
Here’s a quick video showing how to use the different “main” files in the sample code…
|Section 2: How to use the Jumper Lib|
There’s a lot of code included with the Jumper library and if you’re into that kind of thing, diving in and exploring is kind of fun. But you don’t have to understand exactly how it works to use it in your games any more than you need to understand an internal combustion engine in order to drive a car.
So while there are a lot of options that can be tweaked with Jumper, what we’re going to cover here are the basics of getting it up and running.
This demo uses the main.lua file from the sample code project.
Sometimes you can create a walkable map ahead of time, and sometimes you need to build the map at game time. That’s what we’ll do in this video.
The demo code has some cool features you may want to incorporate into your own games, including a drawer that slides from the top of the screen allowing the player to choose objects. In this demo we’re using it as an in-game editor.
This video uses the main-tanksalot.lua file in the project code.
Building a Map on the Fly, Part 2
What happens if you calculate a path for Monster A to the hero and then the hero moves? The monster should react accordingly and find the best path from where it is now to the new location of the hero (target).
That’s what this demo will do. Bit instead of just using one monster, we spawn five bad guys from random locations every time the hero moves on the screen. And when the hero moves, all the on-screen bad guys adjust their paths and continue heading for him.
I recorded this tutorial video the day Corona Labs announced they nabbed John Romero as a CL Advisor, so I decided the graphics in this demo should be from the game Dangerous Dave, which John programmed in 1991. You can read the Dangerous Dave Saga on his site.
The code for this demo is main-hordes.lua in the project files.
Pathfinding isn’t needed for every game, but if you have a character moving from one place to another on the screen it may come in handy. For example, take a look at this scene from The Secret of Monkey Island:
If you want Guybrush Threepwood to walk to the fireplace you’re going to want at leastsome pathfinding so he doesn’t walk through the table of pirates.
And yet, that game doesn’t look like it’s built on a grid.
In this demo I’m going to show you how to use the Tiled software to create an invisible map that can be used with Jumper lib for a game like this.
This demo uses the main-gamescreen.lua file from the project code.
|Section 3: Extras|
In your grid/map you may want to have multiple values to mean walkable. This can often happen when using different tiles to show dirt, stone, wood, etc.
This quick video shows how to create a “walkable” function to be used instead of a variable holding a single value.
In the sample code and videos I stuck to the “basics” of Jumper to make sure you could fully grok how to use it in your games.
But it can do so much more. Watch this video to find out about tunneling and clearance, two things that could be vital for your game to have.
More Corona SDK TutorialsPreview
Jay has been programming professionally since 1988, starting with game programming and then over the years moving to internet programming with a major Seattle telecommunications firm. Jay started programming for mobile devices in 2010 and currently has several games and apps in the Apple App Store with more on the way.
In addition to writing hundreds of technical articles over the years, Jay has recorded dozens of hours of tutorial videos. He's been a speaker at technical conferences and enjoys teaching how to make games and apps almost as much as making games and apps themselves.
Jay is a Certified Developer with Corona SDK, and is also diving into Unity to make 2D games and tutorials.