Difference between revisions of "Jsvx"

From April
Jump to: navigation, search
(Vx_buffer)
Line 8: Line 8:
  
 
=== Vx_buffer ===
 
=== Vx_buffer ===
A vx_buffer is a collection of objects in a vx_world that are rendered together. They represent a group of objects that can be “turned on and off”, similar to a layer in many photo editing platforms. Vx_buffers are also the only way to render objects in Jsvx. To render an object, or collection of objects, you follow these steps.
+
A vx_buffer is a collection of objects in a vx_world that are rendered together. They represent a group of objects that can be “turned on and off”, similar to a "layer" in many photo editing platforms. Vx_buffers are also the only way to render objects in Jsvx. To render an object, or collection of objects, you follow these steps.
 
* Ask the vx_world for a named buffer. (if a buffer with that name exists, the vx_world will return a pointer to the existing buffer)
 
* Ask the vx_world for a named buffer. (if a buffer with that name exists, the vx_world will return a pointer to the existing buffer)
 
  vx_buffer_t *vb = vx_world_get_buffer(vw, "buffer_name");
 
  vx_buffer_t *vb = vx_world_get_buffer(vw, "buffer_name");

Revision as of 19:31, 2 April 2015

The Building Blocks

Before we dive in, we need to discuss the basic building blocks of an application in Jsvx.

Vx_world

A vx_world is a collection of objects that can be rendered in the same scene. Most simple applications only need one vx_world, but nothing says you can’t have more. You can think of a vx_world as a setting, a scene, or a room. If objects can appear in the same camera frame, they need to be in the same vx_world. A vx_world is created with a call to vx_world_create:

vx_world_t *vw = vx_world_create();

Vx_buffer

A vx_buffer is a collection of objects in a vx_world that are rendered together. They represent a group of objects that can be “turned on and off”, similar to a "layer" in many photo editing platforms. Vx_buffers are also the only way to render objects in Jsvx. To render an object, or collection of objects, you follow these steps.

  • Ask the vx_world for a named buffer. (if a buffer with that name exists, the vx_world will return a pointer to the existing buffer)
vx_buffer_t *vb = vx_world_get_buffer(vw, "buffer_name");
vx_buffer_add_back(vb, obj);
  • Swap the buffer.
vx_buffer_swap(vb);

Vx_canvas

A Vx_canvas represents a portion of a literal display device such as a computer monitor or a phone screen. (Does it? look through the code). Webvx will create a canvas for you and pass it to on_create_canvas and on_destroy_canvas.

Vx_layer

A vx_layer represents a “view” into a vx_world. It acts like a moveable camera that inspects the scene (the vx_world). Vx_layers are also responsible for communicating user-initiated events such as mouse clicks and keystrokes to the server system. Much like vx_buffers with vx_worlds, you ask a vx_canvas for a named vx_layer.

vx_layer_t *vl = vx_canvas_get_layer(vc, "layer_name");