Sphere 2 API Reference

From Spheriki

Jump to: navigation, search

Contents

General

System

  • UpdateSystem(): Update Sphere's internal state.
  • GetSphereVersion(): Return Sphere version information.
  • GetPlatform(): Return the platform as string.
  • GetTime(): Return elapsed time in seconds since midnight 1/1/1970.
  • GetTimeInfo([time, utc]): Return time information.
  • GetTicks(): Return elapsed time in milliseconds since Sphere's initialization.
  • Sleep(ms): Suspend Sphere's process until at least ms milliseconds have elapsed.

Compiling Scripts

  • CompileString(string [, name]): Compile the script in string.
  • CompileBlob(blob [, name, offset, count]): Compile the script in blob.
  • CompileStream(stream [, name, count]): Compile the script in stream.

Evaluating Scripts

Serialization

  • JSONStringify(object): Stringify object to JSON (JavaScript Object Notation).
  • JSONParse(jsonstr): Parse jsonstr as JSON string and return the result.
  • DumpObject(object, stream): Serialize object to stream.
  • LoadObject(stream): Deserialize a previously serialized object from stream.

Debugging

  • Assert(expr): Throw an exception if expr evaluates to false.

Math

Math Constants

  • Math.PI: 3.14159
  • Math.PI_2: Math.PI / 2
  • Math.PI_4: Math.PI / 4
  • Math.M_1_PI: 1 / Math.PI
  • Math.M_2_PI: 2 / Math.PI
  • Math.E: 2.71828
  • Math.DEGTORAD: Math.PI / 180
  • Math.RADTODEG: 180 / Math.PI
  • Math.SQRT1_2: 0.70711
  • Math.SQRT_2: 1.41421
  • Math.LN2: 0.69315
  • Math.RAND_MAX: Maximum value returned by Math.rand.

I/O

  • Stream interface: Represents an arbitrary source to read from or to write to.
  • File object: Represents a file source.
  • Blob object: Wraps a block of memory.

File System

  • FileExists(filename): Return whether filename corresponds to a file or directory.
  • IsFile(filename): Return whether filename corresponds to a regular file.
  • IsDirectory(filename): Return whether filename corresponds to a directory.
  • GetFileSize(filename): Return the size of a file.
  • GetFileModTime(filename): Return the last modification time of a file.
  • CreateDirectory(directory): Create a directory.
  • RemoveFile(filename): Remove a file or directory.
  • RenameFile(from, to): Rename a file or directory.
  • EnumerateFiles(directory): Return a list of files and subdirectories contained in directory.

Graphics

  • Canvas object: Holds a image representation in memory.
  • Texture object: Holds a image representation in video memory.

Color

  • CreateColor(red, green, blue [, alpha]): Create a RGBA value.
  • UnpackRed(color): Return the red component of a RGBA value.
  • UnpackGreen(color): Return the green component of a RGBA value.
  • UnpackBlue(color): Return the blue component of a RGBA value.
  • UnpackAlpha(color): Return the alpha component of a RGBA value.

Predefined Colors

  • BLACK: RGBA value (0, 0, 0, 255)
  • WHITE: RGBA value (255, 255, 255, 255)
  • RED: RGBA value (255, 0, 0, 255)
  • GREEN: RGBA value (0, 255, 0, 255)
  • BLUE: RGBA value (0, 0, 255, 255)
  • YELLOW: RGBA value (255, 255, 0, 255)

Display

Game Window

Window Events

Window Buffer

  • SwapWindowBuffers(): Show the effects of the last drawing operations in the game window.

Frame Buffer

  • GetFrameScissor(): Return the rectangular area in the frame buffer where drawing operations will have an effect.
  • SetFrameScissor(scissor): Define the rectangular area in the frame buffer where drawing operations will have an effect.
  • GetBlendMode(): Return current blend mode.
  • SetBlendMode(blendMode): Set blend mode.
  • CloneFrame([section]): Clone the contents of the frame buffer.
  • CaptureFrame(ox, oy, width, height): Capture a section of the frame buffer.
  • DrawCapture(ox, oy, width, height, x, y [, mask]): Draw a previously captured frame buffer section.
  • DrawCaptureQuad(ox, oy, width, height, x1, y1, x2, y2, x3, y3, x4, y4 [, mask]): Draw a transformed previously captured frame buffer section.

Drawing Primitives

  • DrawPoint(x, y, color): Draw a point.
  • DrawLine(x1, y1, x2, y2, col1 [, col2]): Draw a line.
  • DrawTriangle(x1, y1, x2, y2, x3, y3, col1 [, col2, col3]): Draw a triangle.
  • DrawRect(x, y, width, height, col1 [, col2, col3, col4]): Draw a rectangle.

Drawing Images

  • DrawImage(image, x, y [, mask]): Draw an image.
  • DrawSubImage(image, ox, oy, width, height, x, y [, mask]): Draw a section of an image.
  • DrawImageQuad(image, x1, y1, x2, y2, x3, y3, x4, y4 [, mask]): Draw a transformed image.
  • DrawSubImageQuad(image, ox, oy, width, height, x1, y1, x2, y2, x3, y3, x4, y4 [, mask]): Draw a transformed section of an image.
  • DrawTexturedTriangle(texture, tx1, ty1, tx2, ty2, tx3, ty3, x1, y1, x2, y2, x3, y3 [, mask]): Draw a triangle textured with the contents from texture.

Audio

  • Sound object: Holds sound data.
  • SoundEffect object: Holds sound data suitable for sound effects.

Raw Input

Joystick

Joystick Force Feedback

Utility

  • Rect object: Holds position and dimensions of a rectangular area.
  • Vec2 object: Holds a two-dimensional vector.

Compression

  • ZStream object: Holds a Deflate stream state.
Personal tools