An overview of scripts in PlayCanvas

This tutorial will not show how to write code in PlayCanvas just yet, but will give you an overview of how scripts work in PlayCanvas and the structure of a basic script. It is important to watch this tutorial first especially if you don’t have any coding experience in JavaScript. The next tutorial will show you how to start writing your JavaScript code for your games.

Here is the sample code from the tutorial (it is just a template and doesn’t actually make your game do anything):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
pc.script.create('test', function (app) {
 // Creates a new Test instance
 var Test = function (entity) {
 this.entity = entity;
 };
 
 Test.prototype = {
 // Called once after all resources are loaded and before the first update
 initialize: function () {
 },
 
 // Called every frame, dt is time in seconds since last update
 update: function (dt) {
 }
 };
 
 return Test;
});