TGB/PlatformerStarterKit/UsefulActions

From TDN

As better methods and practices are discovered, will update accordingly.

Contents

Spawn code

If you want to spawn something via script you'd do the following.

	%myNewObject = new "t2dAnimatedSprite" or "pskActor2D" or "pskActor3D" or "t2dAnimatedSprite" or "t2dStaticSprite" or "t2dSceneObject"
	{
	SceneGraph = sceneWindow2D.getSceneGraph();
	Config     = %configuration;
  
	Position = %targetPosition;
	};

So if you wanted to spawn say the Dragon you would do the following:

	%myNewObject = new pskActor2D;
	{
	SceneGraph = sceneWindow2D.getSceneGraph();
	Config     = DragonActorTemplate;
  
	Position = %targetPosition;
	};

Pausing the game

Within PlayerMethods.cs within the section onAddToScene add the following:

$mainSceneGraph = sceneWindow2D.getSceneGraph();

This will record the scenegraph player is in so you can use it for later via code. To pause the game:

//This is how you pause
$mainSceneGraph.setScenePause(true);

//This is how you unpause
$mainSceneGraph.setScenePause(false);

Setting collision layers through script

If you want to set the collision layers of what an object will collide with.

	%this.setCollisionLayers("0 1 2 3 4 5 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31");
	%this.setCollisionGroups("0 1 2 3 4 5 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31");

If you want to set a particular layer.

	%this.setLayer("6");
	%this.setGraphGroup("6");

Editing the collision polygons through code.

The first number is how many points there, remember that every point has two locations.

	%this.setCollisionPolyCustom(4, "1.000 1.000 -1.000 -1.000 1.000 1.000 -1.000 -1.000");