Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Documentation

Main loop

A typical main loop will look like this:

  while(!quit)
  {
    arc.time.process();
    // call process for other arc modules, like arc.input

    // update state here
    // scenegraph uses:
    //   arc.scenegraph.advancable.advanceScenegraph(arc.time.elapsedMilliseconds);

    arc.window.clear();
    // draw frame here
    // scenegraph uses: 
    //   arc.scenegraph.drawable.drawScenegraph();
    arc.window.swap();

    arc.time.limitFPS(40);
  }

Note that the fully qualified names were only used for clarity. The call to arc.scenegraph.advancable.advanceScenegraph could just as well have been advanceScenegraph(elapsedMilliseconds);.

Sound

How do I use arc.sound?

GUI

How do I use arc.gui?

Scenegraph

When to use it?

Using the scenegraph enables you to

  • easily express spatial relationships,
  • implement scrolling in a simple way,
  • use the physics engine.

So a card game will probably not use it, a breakout clone might use it and a scrolling action game will definitely want to use it.

What is it?

A scenegraph is basically a tree structure to organize your objects and effects in. Every scenegraph node has one (or sometimes many) parents and some nodes have children. Attributes from parent nodes carry over to their child nodes: most notably the coordinates of children are relative to their parent's. There are more kinds of nodes than just coordinate transformations and graphics though. There are nodes that control the order of drawing, there could be effect nodes that force everything below them to be drawn in a tinted color.

How do I use it?

There is a global root node for the scenegraph: arc.scenegraph.root.rootNode. Methods like drawScenegraph, advanceScenegraph start with it and work their way down the tree.

Sprite node

Nodes in Arc

Base nodes

The fundamental nodes are found in arc.scenegraph.node:

  • Node: abstract base of all nodes, provides traversal methods
  • SingleParentNode and MultiParentNode: most nodes will only have a single parent, but some leaf nodes are allowed multiple parents
  • GroupNode: can have children
  • CompositeNode and CompositeGroupNode: see section about them
  • INotifyOnChildrenAddRemove: interface for nodes that want to get notified about all children added or removed somewhere below them in the tree

Composite nodes

Often you want to make a set of nodes act like one. For example a spaceship might consist of a physics node, several animation nodes and a MouseNotifyNode. In these cases use the CompositeNode and CompositeGroupNode.

Word about SpriteNode.

Graphics nodes

  • FrameNode: draws a texture
  • LinearAnimation: not a node itself, but a factory of nodes; creates animations

Control and effect nodes

  • TransformNode: one of the most often used nodes, simply moves, rotates and scales the scene
  • DrawOrderNode: controls the order in which things are drawn
  • MouseNotifyNode: use for mouse interactivity

Physics

How do I use it?

Create a arc.physics.world.World node and add some arc.physics.mybody.Body-derived nodes (currently Box and Circle from arc.physics.shapes) to it. Their translation, rotation, ... properties will be updated when advanceScenegraph is run. You'll have to add some drawable nodes to these to actually see something.

You can hook up to the collision events by using the signals in Body. If you want Circles and Boxes to collide, you need to import arc.physics.colliders.boxcircle.