Building Up A Basic Demo With PlayCanvas

Create immersive 3D web experiences with the powerful PlayCanvas game engine. This guide covers both code-first and visual-first approaches to building interactive 3D demos.

Introduction to PlayCanvas

PlayCanvas is a powerful web-based 3D game engine that enables developers to create immersive interactive experiences directly in modern browsers. Unlike traditional game engines that require downloads and installations, PlayCanvas runs entirely in the cloud, offering both a code-based engine approach for experienced programmers and a visual editor for rapid prototyping.

Whether you're building your first 3D scene or developing a complex game, PlayCanvas provides the tools and flexibility to bring your creative visions to life with WebGL technology. This guide walks you through building a basic demo using both the PlayCanvas Engine (code-first approach) and the PlayCanvas Editor (visual-first approach), giving you a comprehensive foundation for your 3D web development journey.

What you'll learn:

  • Understanding PlayCanvas products: Engine vs Editor
  • Setting up your development environment
  • Creating 3D scenes with entities and components
  • Lighting, materials, and visual styling
  • Script-based animation techniques
  • Complete code examples and visual workflows

To learn more about modern web technologies that power 3D experiences, explore our JavaScript development services and discover how we build cutting-edge web applications.

Two Ways to Build with PlayCanvas

Choose the development approach that fits your skills and project needs

PlayCanvas Engine

Code-first approach for experienced programmers. Full control over every aspect of 3D rendering and game logic through the JavaScript API.

PlayCanvas Editor

Visual-first approach with drag-and-drop scene building. Real-time collaboration and instant feedback as you create.

PlayCanvas React

Declarative component-based interface for React developers. Integrate 3D graphics seamlessly into React applications.

PlayCanvas Web Components

Standards-based custom HTML elements. Framework-agnostic approach using native web technologies.

Setting Up: Engine-Based Development

Loading PlayCanvas from CDN

The simplest way to get started with PlayCanvas Engine is by loading it from a CDN. Add this script tag to your HTML file:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/build/playcanvas.min.js"></script>

HTML Starter Template

<!DOCTYPE html>
<html lang="en-GB">
 <head>
 <meta charset="utf-8" />
 <title>PlayCanvas Demo</title>
 <style>
 html, body, canvas {
 margin: 0;
 padding: 0;
 width: 100%;
 height: 100%;
 }
 </style>
 </head>
 <body>
 <canvas id="application-canvas"></canvas>
 <script src="playcanvas.min.js"></script>
 <script>
 const canvas = document.getElementById("application-canvas");
 // Your PlayCanvas code here
 </script>
 </body>
</html>

This template sets up a full-screen canvas and loads the PlayCanvas engine for immediate 3D development. The engine handles all WebGL initialization, frame updates, and rendering complexity, allowing you to focus on creating compelling 3D content.

Setting Up: Editor-Based Development

Creating Your Account

  1. Visit playcanvas.com and sign up for a free account
  2. Complete the registration process
  3. You'll see your canvas homepage with project management options

Creating a New Project

  1. Click the "New" button on your dashboard
  2. Select "Blank Project" for a clean starting point
  3. Enter a project name (e.g., "PlayCanvas Demo")
  4. Click "Create" to launch the Editor workspace

The Editor provides a complete visual development environment with real-time preview, asset management, and collaboration features--all running in your browser without installation. According to the MDN PlayCanvas Editor guide, new projects include optional starter tutorials that help familiarize you with the workspace before beginning your own project.

Editor Interface Overview

Viewport - The main area showing your 3D scene in real-time. Drag to rotate the camera view, scroll to zoom, and use gizmos to transform objects.

Hierarchy Panel - Left sidebar showing all entities in your scene as a tree structure. Click to select entities for editing.

Inspector Panel - Right sidebar displaying properties of the selected entity. Edit components, materials, and scripts here.

Assets Panel - Bottom panel containing all project assets including scripts, materials, textures, and models.

Launch Button - Top-right button that opens your scene in a new tab for testing and previewing.

As noted in the MDN documentation, the Editor interface provides real-time synchronization across all views, so changes appear instantly as you work.

Creating Your First 3D Scene

The Entity-Component System

PlayCanvas uses an Entity-Component System (ECS) architecture where entities are the fundamental objects in your scene, and components provide their behaviors and properties. This modular approach, as described in the MDN PlayCanvas Engine documentation, makes it easy to compose complex objects from simple pieces and modify behavior at runtime.

Entities are containers that exist in the scene hierarchy. They have a transform (position, rotation, scale) but no inherent functionality.

Components attach to entities to add capabilities--camera, light, model, script, physics, and more. Mix and match components to create complex objects.

Creating Entities

In code:

const entity = new pc.Entity();
entity.addComponent("model", { type: "box" });
app.root.addChild(entity);

In the Editor:

  1. Click the "Add Entity" button (plus icon)
  2. Select the entity type from the dropdown
  3. The entity appears in the Hierarchy and Viewport

Adding a Camera

const camera = new pc.Entity();
camera.addComponent("camera", {
 clearColor: new pc.Color(0.8, 0.8, 0.8)
});
app.root.addChild(camera);
camera.setPosition(0, 0, 7);

The camera is positioned 7 units back on the Z-axis, giving objects room to appear in front of it. Every PlayCanvas project begins with creating the application instance that manages your 3D world, as outlined in the official PlayCanvas getting started guide.

Adding 3D Geometry

Built-in Primitives

PlayCanvas provides several built-in primitive shapes that you can add to your scene immediately without external assets, as documented in the MDN PlayCanvas Engine tutorial:

PrimitiveCode TypeUse Case
Box"box"Cubes, buildings, crates
Sphere"sphere"Planets, balls, rounded objects
Cylinder"cylinder"Pillars, pipes, wheels
Cone"cone"Funnels, spikes, architectural elements

Creating Shapes in Code

// Create a cube
const box = new pc.Entity();
box.addComponent("model", { type: "box" });
app.root.addChild(box);
box.rotate(10, 15, 0);

// Create a sphere
const sphere = new pc.Entity();
sphere.addComponent("model", { type: "sphere" });
app.root.addChild(sphere);
sphere.setPosition(-2, 0, 0);

// Create a cylinder
const cylinder = new pc.Entity();
cylinder.addComponent("model", { type: "cylinder" });
app.root.addChild(cylinder);
cylinder.setPosition(2, 0, 0);

Each primitive creates the appropriate geometry with a single line of code by changing the type parameter.

Creating Shapes in the Editor

  1. Select the parent in the Hierarchy (usually Root)
  2. Click "Add Entity" button in the top-left
  3. **Choose a dropdown menu:
  • Box shape** from the - Sphere
  • Cylinder
  • Cone
  • Capsule
  • Plane
  • And more...

The new entity appears with default dimensions. Use the transform gizmos in the viewport to:

  • Move: Drag the arrows to position along X, Y, Z axes
  • Rotate: Drag the colored rings to rotate the object
  • Scale: Drag the cubes at gizmo ends to resize

Adjust exact values in the Inspector panel for precision positioning. As described in the MDN Editor guide, the Editor displays your scene as a hierarchy tree, making it easy to understand relationships between objects.

For complex 3D projects, our custom web application development team can help you build sophisticated visualizations and interactive experiences.

Lighting Your Scene

Directional Light

Directional light simulates sunlight--rays are parallel and come from a specific direction:

const light = new pc.Entity();
light.addComponent("light", {
 type: "directional",
 color: new pc.Color(1, 1, 1),
 intensity: 1
});
app.root.addChild(light);
light.setEulerAngles(45, 30, 0);

Ambient Light

Ambient light fills shadows with base illumination:

app.scene.ambientLight = new pc.Color(0.2, 0.2, 0.2);

A value of 0.2 provides subtle fill without washing out contrast. As explained in the MDN PlayCanvas Engine documentation, ambient light prevents objects from appearing pitch black on their shadowed sides.

Lighting Types

TypeDescriptionBest For
DirectionalParallel rays, like sunlightOutdoor scenes, global illumination
PointRadiates from a point in all directionsLight bulbs, torches, indicators
SpotConical light from a pointFlashlights, spotlights, stage lighting

Editor Lighting Workflow

  1. New projects include a pre-configured directional light
  2. Select the light to adjust intensity, color, and shadows
  3. Use gizmos to position point and spot lights
  4. Enable "Cast Shadows" for realistic shadow effects

According to the MDN Editor documentation, the Editor simplifies lighting by providing intuitive controls and visual gizmos.

Materials and Colors

Creating Standard Materials

The StandardMaterial is the most commonly used type, supporting realistic surface properties as documented in the MDN PlayCanvas Engine tutorial:

// Create a blue material
const boxMaterial = new pc.StandardMaterial();
boxMaterial.diffuse.set(0, 0.58, 0.86);
boxMaterial.update();

// Apply to the box
box.model.meshInstances[0].material = boxMaterial;

Color values use the 0-1 range, not 0-255:

  • Red: (1, 0, 0)
  • Green: (0, 1, 0)
  • Blue: (0, 0, 1)
  • White: (1, 1, 1)
  • Black: (0, 0, 0)

Material Properties

PropertyDescription
DiffuseBase color of the surface
SpecularHighlight color and intensity
ShininessHow focused highlights appear
EmissiveLight the surface emits
OpacityTransparency level (0-1)

Creating Materials in the Editor

  1. Create a material: Click "Add Asset" → "Material"
  2. Name it descriptively: boxMaterial, cylinderMaterial, etc.
  3. Select the material to open the Inspector
  4. Change the diffuse color: Click the color picker
  5. Apply to objects: Drag the material onto objects

Color Picker Usage

  • Click the color swatch to open the picker
  • Select a color visually or enter a hex value
  • Enter hex without the # symbol (e.g., 0095DD)
  • Press Enter to confirm the color

Managing Multiple Materials

Create separate materials for different objects:

  • boxMaterial - Blue cube
  • cylinderMaterial - Orange cylinder
  • coneMaterial - Gray cone

Descriptive names make it easy to remember which material affects which object as your scene grows. As noted in the MDN Editor guide, creating distinct materials helps organize your scene and makes future modifications easier.

Our front-end development expertise includes working with modern styling technologies that complement 3D graphics.

Script-Based Animation

Creating Animation Scripts

PlayCanvas scripts have initialize() for setup and update() for frame-by-frame logic, as described in the MDN PlayCanvas Engine documentation:

// boxAnimation.js
var BoxAnimation = pc.createScript('boxAnimation');

BoxAnimation.prototype.initialize = function() {
 // Setup code runs once
};

BoxAnimation.prototype.update = function(dt) {
 // Called every frame
 this.entity.rotate(dt * 10, dt * 20, dt * 30);
};

Animation Techniques

Continuous Rotation:

this.entity.rotate(dt * 10, dt * 20, dt * 30);

Pulsing Scale:

this.timer += dt;
const scale = Math.abs(Math.sin(this.timer));
this.entity.setLocalScale(1, scale, 1);

Floating Motion:

const y = Math.sin(Date.now() / 1000) * 0.5;
this.entity.setPosition(0, y, 0);

Delta Time (dt)

The update function receives dt (delta time in seconds)--the time since the last frame. Multiply animation values by dt to create frame-rate-independent animations that run at the same speed on all devices. As documented in the MDN guide, using dt ensures smooth animations regardless of frame rate.

Creating Scripts in the Editor

  1. Add a script asset: Click "Add Asset" → "Script"
  2. Name your script: boxAnimation.js, cylinderPulse.js, etc.
  3. Double-click to edit: Opens the code editor
  4. Write your animation logic in the update() function
  5. Save and return to the main Editor

Attaching Scripts to Entities

  1. Select the entity you want to animate
  2. Click "Add Component" in the Inspector
  3. Select "Script" from the component list
  4. Click your script in the available scripts list

The script is now attached and its update() function runs every frame! According to the MDN Editor documentation, creating scripts in the Editor follows a similar pattern to the engine approach but with visual workflow benefits.

Testing Your Animation

Click the Launch button (top-right) to open your scene in a new browser tab. The animation runs in real-time--make edits in the Editor, save, and refresh to see changes.

Complete Code Example

Here's the complete code for a working PlayCanvas demo with a rotating blue cube, as demonstrated in the MDN PlayCanvas Engine tutorial:

const canvas = document.getElementById("application-canvas");

// Start and init Application
const app = new pc.Application(canvas);
app.start();
app.setCanvasFillMode(pc.FILLMODE_FILL_WINDOW);
app.setCanvasResolution(pc.RESOLUTION_AUTO);

// Create camera
const camera = new pc.Entity();
camera.addComponent("camera", { clearColor: new pc.Color(0.8, 0.8, 0.8) });
app.root.addChild(camera);
camera.setPosition(0, 0, 7);

// Create cube
const box = new pc.Entity();
box.addComponent("model", { type: "box" });
app.root.addChild(box);
box.rotate(10, 15, 0);

// Create light
const light = new pc.Entity();
light.addComponent("light");
light.setEulerAngles(45, 30, 0);
app.root.addChild(light);
app.scene.ambientLight = new pc.Color(0.2, 0.2, 0.2);

// Create cube's material
const boxMaterial = new pc.StandardMaterial();
boxMaterial.diffuse.set(0, 0.58, 0.86);
boxMaterial.update();
box.model.meshInstances[0].material = boxMaterial;

// Animation script
const RotateScript = pc.createScript('rotate');
RotateScript.prototype.update = function(dt) {
 this.entity.rotate(dt * 10, dt * 20, dt * 30);
};
box.addComponent('script');
box.script.create('rotate');

// Handle window resize
window.addEventListener("resize", () => {
 app.resizeCanvas(canvas.width, canvas.height);
});

This demo creates:

  • A light gray background via camera clear color
  • A blue cube with StandardMaterial
  • Directional lighting from an angle
  • Ambient fill light
  • Continuous rotation animation

The PlayCanvas Crash Course provides additional end-to-end game development tutorials covering project setup, asset management, physics, scripting, and animation state graphs for more complex projects.

Frequently Asked Questions

Do I need to install anything for PlayCanvas?

For the Editor approach, no installation is needed--everything runs in your browser. For the Engine approach, you only need the PlayCanvas JavaScript file, which can load from a CDN or download locally.

What's the difference between Engine and Editor?

Engine is code-first, giving you full programmatic control over every aspect. Editor is visual-first, letting you build scenes with drag-and-drop while still supporting custom scripts. Both can be used together in the same project.

Can I use PlayCanvas without an internet connection?

Yes, by downloading the PlayCanvas engine file locally. However, the Editor requires an internet connection as it's cloud-based.

Is PlayCanvas free to use?

PlayCanvas has a free tier with core features. Some advanced features and team collaboration tools require paid plans. Check the PlayCanvas website for current pricing.

What browsers support PlayCanvas?

PlayCanvas works in all modern browsers with WebGL support, including Chrome, Firefox, Safari, and Edge. WebGL 2.0 is recommended for best performance and features.

How do I add physics to my PlayCanvas project?

Add collision and rigidbody components to entities. The collision component defines the shape, while the rigidbody component adds physics properties like mass and friction. The [PlayCanvas Crash Course](https://www.playcanvas.com/tutorials/crash-course/) covers physics integration in detail.

Taking Your Skills Further

Advanced Topics to Explore

  • Physics Simulation: Add realistic object interactions with collision detection and rigidbody dynamics
  • Asset Management: Organize imported models, textures, and sounds efficiently
  • Animation State Graphs: Create sophisticated character animations with blend trees and transitions
  • Particle Systems: Add effects like fire, smoke, sparks, and magic abilities
  • UI Systems: Build menus, HUDs, and interactive interfaces
  • Audio: Add sound effects and background music to your projects
  • Input Handling: Respond to keyboard, mouse, touch, and gamepad input

Learning Resources

  • PlayCanvas User Manual: Comprehensive reference for all features
  • Tutorials Section: Hundreds of step-by-step guides for specific features
  • API Reference: Complete documentation of the JavaScript API
  • Community Forum: Get help from experienced developers
  • Discord Server: Real-time chat with the PlayCanvas community

Start Building Today

With the fundamentals of PlayCanvas mastered, you have everything you need to start creating your own 3D web experiences. Start with simple projects to solidify your understanding, then gradually tackle more complex features as your skills grow. The PlayCanvas community is welcoming and supportive--don't hesitate to ask questions as you learn!

For teams looking to integrate 3D experiences into their web applications, our custom development services can help you leverage PlayCanvas and other modern web technologies to create compelling interactive experiences.

Ready to Build Amazing 3D Web Experiences?

Our team of web development experts can help you create interactive 3D applications, games, and visualizations using PlayCanvas and other modern technologies.