Skip to content
rpg edited this page Dec 21, 2012 · 5 revisions

In Cheetah 2D Engine all objects represent as "Entity". You can create and delete entities, assign events, change draw callbacks, animate objects in different ways. Each entity has a parent, so all entities are merged into one big tree called scene graph.

First, entity is nothing - it is just abstract thing. But you can create anything what you want on it: images, sprites, animated effects, text, sound and so on. Future live of entity depends on its parameters, draw functions and event callbacks.

Creating entities in Cheetah's world is super-easy. First, Cheetah engine creates one global entity - screen. Then you can create your own entities by attaching them to screen as childrens. Your first entity must be child of screen:

local myEntity = Entity:new(screen)

Next, you can create new entity as child of screen or as child of myEntity - your own entity.

local myChildEntity = Entity:new(myEntity)
local myChildEntity2 = Entity:new(screen)

Unnamed Entity

Unnamed Entity - entity without assigned to it variable. Unnamed enity lives until lives all its parents and you cannot acces to it directly.

You can create "unnamed" entitity or link entity to local or global variable. Unnamed objects can not be deleted by the garbage collector. Be accurate with unnamed entities, if you create them dynamically, this may cause memory leaking. Use unnamed entities only for static objects that must live all time while application is running.

--this is unnamed entity
Entity:new(screen)

After allocation you cannot get access to it more. You may access to this entity only using _screen.child array. Entities without name may be used in Cheetah engine very intensively: background images, static images, objects, that live all time: button objects, indicators, user interface objects.


Tutorials | Documentation Language: English | Русский

Clone this wiki locally