Objects

Tables and functions are objects; variables do not actually contain these values, only references to them. Tables are also used in what is known as object-oriented programming. Variables and methods that manipulate those variables can be collected together into objects. Such a value is called an object, and its functions are called methods. In Corona, we'll focus more on display objects since they are essential for game development.

Anything drawn on the screen is made by display objects. In Corona, the assets you see displayed in the simulator are instances of display objects. You have probably seen shapes, images, and text, which are all forms of display objects. When you create these objects, you'll be able to animate them, turn them into backgrounds, interact with them using touch events, and so on.

Display objects are created by calling a function known as a factory function. There is a specific kind of factory function for each type of display object. For example, display.newCircle() creates a vector object.

Instances of display objects behave in a manner similar to Lua tables. This enables you to add your own properties to an object as long as they do not conflict with the system-assigned properties and method names.

The dot operator is used to access properties. Display objects share the following properties:

Corona can create display objects to store object methods as properties. There are two ways this can be done: using the dot operator (".") or using the colon operator (":"). Both are valid ways to create object methods.

This is an example of the dot operator:

This is an example of the colon operator:

The call to an object method using the dot operator is passed to the object if it's the first argument. The colon operator method is merely a shortcut with less typing involved to create the function.

Display objects share the following methods: