|
Deki 0.40.1
비주얼 에디터가 있는 2D·3D 모듈식 C++ 엔진
|
이 가이드는 아직 번역되지 않았습니다.
Everything an object does comes from its components. This page is how to write your own.
In the Asset Browser, open Scripts, right-click and choose Create C++ Script. Replace the two files with this:
src/Player.h:
src/Player.cpp:
Save, and the editor rebuilds your code. Add Component now lists Player.
DEKI_EXPORT shows a field in the Inspector and saves it in the scene. It works on numbers, bool, std::string, Deki::Color and references to objects and assets.
DEKI_TOOLTIP adds the text shown on hover, and DEKI_RANGE limits the value.
| Method | When |
|---|---|
| Awake | Once, when the object is ready. Set up the component itself here. |
| Start | Once, after every Awake. Talk to other components here. |
| Update | Every frame. |
Declare only the ones you need. A component with no Update costs nothing per frame.
On the same object:
To reach another object, add a field and pick the object in the Inspector:
Get() returns nothing if the field is empty or the object has gone, so check it when either can happen. You can also find an object by name:
To make many copies of something you built in the editor, save it as its own scene and point a field at it. Each call makes a copy and returns its root:
Remove an object with scene->DestroyDekiObject(coin). It is safe from inside any component, including one on that object.
The old scene is freed before the next one loads, so the two are never in memory together.
DEKI_LOG_WARNING and DEKI_LOG_ERROR work the same way. They need #include <deki/LogSystem.h>. On a device the text goes to the serial port.