Reader small image

You're reading from  Torque 3D Game Development Cookbook

Product typeBook
Published inJan 2013
Reading LevelIntermediate
PublisherPackt
ISBN-139781849693547
Edition1st Edition
Languages
Right arrow
Author (1)
DAVID WYAND
DAVID WYAND
author image
DAVID WYAND

David Wyand has been using GarageGames' Torque Game Engine for the past 10 years. Among his other interestes are 3D graphics applications, computer networking and Artificial Intelligence for computer games.
Read more about DAVID WYAND

Right arrow

Creating a new singleton


A singleton is a SimObject instance that we only ever want one instance of. Typically we use singletons for shader objects, materials, and some audio objects. In this recipe we will learn how to create an object as a singleton.

How to do it...

Creating a singleton is straight forward. Here we will create a Material singleton, one of a number of SimObject classes that may be created as a singleton, as follows:

singleton Material(DECAL_scorch)
{
   baseTex[0] = "./scorch_decal.png";
   translucent = true;
   translucentBlendOp = None;
   translucentZWrite = true;
   alphaTest = true;
   alphaRef = 84;
};

How it works...

We use the singleton keyword when creating a new SimObject class object that we want only one instance of, and always give a unique global name to it. Other than ensuring that only one instance of this object will exist, the creation process is exactly the same as when the new keyword was used.

See also

  • Creating a new SimObject instance

  • Creating a new internal name only SimObject instance

  • Creating a new Datablock object

Previous PageNext Page
You have been reading a chapter from
Torque 3D Game Development Cookbook
Published in: Jan 2013Publisher: PacktISBN-13: 9781849693547
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
DAVID WYAND

David Wyand has been using GarageGames' Torque Game Engine for the past 10 years. Among his other interestes are 3D graphics applications, computer networking and Artificial Intelligence for computer games.
Read more about DAVID WYAND