Sphere 2 API Reference
From Spheriki
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
- EvaluateString(string): Evaluates string.
- EvaluateScript(name): Evaluates the script name.
- RequireScript(name): Evaluates the script name only if not already evaluated.
- GetLoadedScripts(): Return a list of scripts evaluated using RequireScript.
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.cos(x): Compute cosine.
- Math.sin(x): Compute sine.
- Math.tan(x): Compute tangent.
- Math.acos(x): Compute arc cosine.
- Math.asin(x): Compute arc sine.
- Math.atan(x): Compute arc tangent.
- Math.atan2(y, x): Compute arc tangent with two parameters.
- Math.cosh(x): Compute hyperbolic cosine.
- Math.sinh(x): Compute hyperbolic sine.
- Math.tanh(x): Compute hyperbolic tangent.
- Math.exp(x): Compute exponential function.
- Math.log(x): Compute natural logarithm.
- Math.log2(x): Compute binary logarithm.
- Math.log10(x): Compute common logarithm.
- Math.pow(base, exponent): Raise to power.
- Math.sqrt(x): Compute square root.
- Math.ceil(x): Round up value.
- Math.floor(x): Round down value.
- Math.round(x): Round value.
- Math.abs(x): Compute absolute value.
- Math.min(a, b): Return the lesser of two arguments.
- Math.max(a, b): Return the greater of two arguments.
- Math.rand(): Generate random number.
- Math.randf(): Generate random number in the range 0 to 1.
- Math.easeIn(startVal, endVal, curVal): Compute an eased value.
- Math.easeOut(startVal, endVal, curVal): Compute an eased value.
- Math.easeInOut(startVal, endVal, curVal): Compute an eased value.
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
- GetDefaultDisplayMode(): Return the default display mode.
- EnumerateDisplayModes(): Return a list of supported display modes.
Game Window
- SetWindowMode(width, height, fullscreen): Set the game window mode.
- GetWindowWidth(): Return the width of the game window.
- GetWindowHeight(): Return the height of the game window.
- IsWindowFullScreen(): Return whether the game window is full-screen.
- IsWindowActive(): Return whether the game window is active.
- GetWindowTitle(): Return the window title of the game window.
- SetWindowTitle(title): Set the window title of the game window.
- SetWindowIcon(icon): Set the icon of the game window.
Window Events
- PeekWindowEvent([event]): Return whether there are any window events pending.
- GetWindowEvent(): Return the next window event.
- ClearWindowEvents(): Clear the window event queue.
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
- GetNumJoysticks(): Return the number of attached joysticks.
- GetJoystickName(joy): Return the device name of a joystick.
- GetNumJoystickButtons(joy): Return the number of buttons on a joystick.
- GetNumJoystickAxes(joy): Return the number of axes on a joystick.
- GetNumJoystickHats(joy): Return the number of POV hats on a joystick.
- IsJoystickButtonDown(joy, button): Return whether joystick button is currently being held down.
- GetJoystickAxis(joy, axis): Return the axis value of a joystick.
- GetJoystickHat(joy, hat): Return the POV hat value of a joystick.
Joystick Force Feedback
- IsJoystickHaptic(joy): Return whether a joystick has Force Feedback.
- CreateJoystickForce(joy, strength, duration): Create a force effect on a joystick.
- ApplyJoystickForce(joy, force [, times]): Apply a force to a joystick.
- StopJoystickForce(joy, force): Stop a force applied to a joystick.
- StopAllJoystickForces(joy): Stop all forces applied to a joystick.
- DestroyJoystickForce(joy, force): Destroy a force effect on a joystick.
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.