Acron Engine Key Facts¶
Everything below assumes Python scripting against the Acron C++ core.
Scene Graph¶
All 3D objects live in a tree rooted at
render; 2D/UI objects live underrender2d.Every node is accessed through a
NodePathhandle — never manipulateAcronNodedirectly.Parent-relative transforms:
node.setPos(x, y, z),node.setHpr(h, p, r),node.setScale(s).World-space transform:
node.getPos(render),node.getMat(render).Attach to scene:
node.reparentTo(parent). Remove:node.detachNode()(keeps alive) ornode.removeNode()(destroys).
Game Loop¶
ShowBase.run()starts the loop. Never write a manualwhile True.Tasks registered with
taskMgr.add(fn, 'name', sort=N)are called once per frame in ascending sort order.Return
task.contto keep running,task.doneto stop.Delta time:
globalClock.getDt()ortask.dtinside the task function.Deferred single-shot:
taskMgr.doMethodLater(seconds, fn, 'name').
Events (Observer / Messenger)¶
messenger.send('event-name', [arg1, arg2])— fire an event from anywhere.Classes inherit
DirectObjectand callself.accept('event-name', handler)to subscribe.Unsubscribe:
self.ignore('event-name')orself.ignoreAll()(call in everydestroy()).Input events are strings:
'w','w-up','mouse1','arrow_left'.
Finite State Machine¶
from direct.fsm.FSM import FSM— inherit, don’t hand-roll.Define
enterStateName()/exitStateName()method pairs.Transition:
self.request('StateName'). Restrict withdefaultTransitionsdict.Always call
self.cleanup()on destruction.
Animation & Intervals¶
Static models:
loader.loadModel('file.bam')→NodePath.Animated models:
Actor('model.bam', {'anim': 'anim.bam'}). Play:.loop('anim'),.play('anim'),.stop().Timed sequences:
Sequence(LerpPosInterval(node, t, pos), FunctionInterval(fn), Wait(t)).Start:
seq.start()/seq.loop(). All intervals managed byivalMgr.
Memory & Cleanup¶
Nodes are reference-counted. A
NodePathnot reparented into the scene graph and with no Python reference will be garbage-collected.Pattern: hide inactive objects (
node.hide()) rather than destroying and re-creating them (see Object Pool).ModelPoolcaches model files —loader.loadModel()is safe to call repeatedly with the same path.
Audio¶
Load:
loader.loadSfx('file.ogg')(sound effect) /loader.loadMusic('file.ogg')(music).Play:
sound.play(). Stop:sound.stop(). Loop:sound.setLoop(True).3D positional audio: attach an
AudioSound3Dto aNodePath.
Collision¶
Add a solid to a
CollisionNode, reparent to the entity’s rootNodePath.Global traverser:
base.cTrav = CollisionTraverser().Filter with bitmasks:
cn.setFromCollideMask(BitMask32.bit(0)).Handlers:
CollisionHandlerPusher(physics response),CollisionHandlerEvent(fire events),CollisionHandlerQueue(manual query).
Useful Globals¶
Global |
Type |
Purpose |
|---|---|---|
|
|
Window, camera, mouse, audio managers |
|
|
Add / remove / query tasks |
|
|
Send and receive events |
|
|
Load models, textures, sounds |
|
|
Track running intervals |
|
|
Delta time, frame time, frame rate |
|
|
Root of the 3D scene graph |
|
|
Root of the 2D / UI scene graph |
|
|
Default camera node |