Demo - Construct 3

How to use behavior TileMovement

View the Project on GitHub el3um4s/construct-demo

View my Blogblog.stranianelli.com

How to use behavior TileMovement

global_runtime.js

runOnStartup(async  runtime =>  {  globalThis.g_runtime  =  runtime })

c3_tile_movement_helper.js

function SimulateControl(uid, direction) {
	const objectUID = g_runtime.getInstanceByUid(uid).behaviors.TileMovement;
	const canMove = CanMoveTo(uid, direction)
	if (canMove) objectUID.simulateControl(direction);
	return canMove;
}

function CanMoveTo(uid, direction) {
	const objectUID = g_runtime.getInstanceByUid(uid).behaviors.TileMovement;
	const position = objectUID.getGridPosition();
	const x = position[0];
	const y = position[1];

	let canMove = false;

	switch (direction.toLowerCase()) {
		case "left":
			canMove =  objectUID.canMoveTo(x-1,y);
		break;
		case "right":
			canMove =  objectUID.canMoveTo(x+1,y);
		break;
		case "up":
			canMove =  objectUID.canMoveTo(x,y-1);
		break;
		case "down":
			canMove =  objectUID.canMoveTo(x,y+1);
		break;
		default:
			canMove = false;
		break;
	}

	return canMove;
}