enablePath() Function Reference

enablePath(integer frame, string direction)

Enables movement from a particular tile frame, on a particular direction. Also enables movement to the tile from the reverse of that direction. So if you enable 'north', characters will be able to leave the tile by walking upwards, or enter the tile by walking downwards.

Additionally, when characters move directly north, east, south or west - therefore crossing adjacent tiles - Qiso factors in whether those tiles can be crossed on their north, east, south or west points. For example to walk east, the origin tile must allow east, the destination tile must allow west, the northern adjacent tile must allow south and the southern adjacent tile must allow north.

Frame should be given as a numeric reference matching the references used in the Qiso or Tiled map data.

Rather than calling enablePath() hundreds of times, refer to the loadTiledMap() documentation as Qiso can now set all of this up internally, using custom tile properties.

In pathfinding mode 1, tiles have all directions enabled by default so you would only need to call this if using pathfinding mode 2, or if re-enabling movement that was previously disabled. Although generally, for things like a door you'd have separate open and closed graphics as two different frames and add/remove the appropriate tile layer to handle that so simply disabling movement for the closed variant would suffice.


	local qiso = require "plugin.qisoengine"
	qiso.setAssetsFolder("assets")
	qiso.loadTiledMap("sample-tilemap")

	-- Prevent walking through walls.
	qiso.disablePath(9, "south-east")
	qiso.disablePath(9, "east") -- SE wall
	qiso.disablePath(9, "south")

	qiso.disablePath(10, "north-east")
	qiso.disablePath(10, "east") -- NE wall
	qiso.disablePath(10, "north")

	qiso.disablePath(11, "north-west")
	qiso.disablePath(11, "west") -- NW wall
	qiso.disablePath(11, "north")

	qiso.disablePath(12, "south-west")
	qiso.disablePath(12, "west") -- SW wall
	qiso.disablePath(12, "south")

	-- Enable walking through walls again.
	qiso.enablePath(9, "south-east")
	qiso.enablePath(9, "east") -- SE wall
	qiso.enablePath(9, "south")

	qiso.enablePath(10, "north-east")
	qiso.enablePath(10, "east") -- NE wall
	qiso.enablePath(10, "north")

	qiso.enablePath(11, "north-west")
	qiso.enablePath(11, "west") -- NW wall
	qiso.enablePath(11, "north")

	qiso.enablePath(12, "south-west")
	qiso.enablePath(12, "west") -- SW wall
	qiso.enablePath(12, "south")

	-- Load a spritemap for use as a character. Sequences must be given compass names, like this...
	local playerMap = graphics.newImageSheet(qiso.getAssetsFolder() .. "/dummy.png", { width = 256, height = 512, numFrames = 64, border = 0 })
	local playerSprites = {
		{ name = 'standing-north', frames = { 25 } },
		{ name = 'standing-north-east', frames = { 17 } },
		{ name = 'standing-east', frames = { 9 } },
		{ name = 'standing-south-east', frames = { 1 } },
		{ name = 'standing-south', frames = { 57 } },
		{ name = 'standing-south-west', frames = { 49 } },
		{ name = 'standing-west', frames = { 41 } },
		{ name = 'standing-north-west', frames = { 33 } },

		{ name = 'walking-north', frames = { 25, 26, 27, 28, 29, 30, 31, 32 }, time = 750, loopCount = 0, loopDirection = 'forward' },
		{ name = 'walking-north-east', frames = { 17, 18, 19, 20, 21, 22, 23, 24 }, time = 750, loopCount = 0, loopDirection = 'forward' },
		{ name = 'walking-east', frames = { 9, 10, 11, 12, 13, 14, 15, 16 }, time = 750, loopCount = 0, loopDirection = 'forward' },
		{ name = 'walking-south-east', frames = { 1, 2, 3, 4, 5, 6, 7, 8 }, time = 750, loopCount = 0, loopDirection = 'forward' },
		{ name = 'walking-south', frames = { 57, 58, 59, 60, 61, 62, 63, 64 }, time = 750, loopCount = 0, loopDirection = 'forward' },
		{ name = 'walking-south-west', frames = { 49, 50, 51, 52, 53, 54, 55, 56 }, time = 750, loopCount = 0, loopDirection = 'forward' },
		{ name = 'walking-west', frames = { 41, 42, 43, 44, 45, 46, 47, 48 }, time = 750, loopCount = 0, loopDirection = 'forward' },
		{ name = 'walking-north-west', frames = { 33, 34, 35, 36, 37, 38, 39, 40 }, time = 750, loopCount = 0, loopDirection = 'forward' }
	}

	-- Add a character at tile 6x8 using the dummy spritemap, and then focus the camera on that tile.
	qiso.addCharacter("Player", playerMap, playerSprites, "standing", 6, 8)
	qiso.goTo(6, 8)

	-- Enable camera panning when the screen is dragged
	qiso.enableCameraPan()

	-- Enable the main Qiso loop to render/update our world
	qiso.activate()

	-- Walk the player to the tapped tile
	function tapTile(event)
		-- Get the tile located where the screen was tapped. If there is no tile here, getTile returns nil.
		local tile = qiso.getTile(event.x, event.y)

		if(tile ~= nil) then
			-- path-find to the tapped location, using the walking sequences defined above.
			qiso.moveCharacter("Player", tile.x, tile.y, "walking", 1000)
		end
	end

	-- Do something when the screen is tapped
	Runtime:addEventListener('tap', tapTile)