Difference between revisions of "User:Flying Jester/TurboSphere API"
From Spherical
(Fix API links) |
|||
Line 84: | Line 84: | ||
* surface_or_image.getPixel(x, y) | * surface_or_image.getPixel(x, y) | ||
− | :: Returns a [[color]] object of the color of the Surface or Image at 'x', 'y'. | + | :: Returns a [[API:Color|color]] object of the color of the Surface or Image at 'x', 'y'. |
− | * surface_or_image.setPixel.(x, y, [[color]]) | + | * surface_or_image.setPixel.(x, y, [[API:Color|color]]) |
:: Sets the color of the pixel x, y of surface_or_image to 'color'. | :: Sets the color of the pixel x, y of surface_or_image to 'color'. | ||
− | * surface_or_image.rectangle(x, y, w, h, [[color]]) | + | * surface_or_image.rectangle(x, y, w, h, [[API:Color|color]]) |
:: Draws a rectangle on surface_or_image at 'x', 'y', of width 'w' and height 'h' and fills it with 'color'. | :: Draws a rectangle on surface_or_image at 'x', 'y', of width 'w' and height 'h' and fills it with 'color'. | ||
Line 109: | Line 109: | ||
===Graphics Primitives=== | ===Graphics Primitives=== | ||
− | * Line(x1, y1, x2, y2, [[color]]) | + | * Line(x1, y1, x2, y2, [[API:Color|color]]) |
:: Draws a line of 'color' from x1, y1, to x2, y2. | :: Draws a line of 'color' from x1, y1, to x2, y2. | ||
− | * Point(x, y, [[color]]) | + | * Point(x, y, [[API:Color|color]]) |
:: Draws a point of 'color' at x, y. | :: Draws a point of 'color' at x, y. | ||
− | * Rectangle(x, y, w, h, [[color]]) | + | * Rectangle(x, y, w, h, [[API:Color|color]]) |
:: Draws a rectangle of 'color' width w and height h at x, y. | :: Draws a rectangle of 'color' width w and height h at x, y. | ||
Line 121: | Line 121: | ||
:: Draws a rectangle at x, y, with a width of w and a height of h. The color is faded from c1 to c4 around the corners, moving clockwise from the upper left corner. | :: Draws a rectangle at x, y, with a width of w and a height of h. The color is faded from c1 to c4 around the corners, moving clockwise from the upper left corner. | ||
− | * FilledCircle(x, y, r, [[color]]) | + | * FilledCircle(x, y, r, [[API:Color|color]]) |
::Draws a circle of radius r centered at x, y, filled with 'color'. | ::Draws a circle of radius r centered at x, y, filled with 'color'. | ||
− | * OutlinedCircle(x, y, r, [[color]] | + | * OutlinedCircle(x, y, r, [[API:Color|color]] |
::Draws an outline of a circle of radius r centered at x, y with 'color'. | ::Draws an outline of a circle of radius r centered at x, y with 'color'. | ||
Revision as of 19:49, 20 May 2013
This page documents the TurboSphere API. Currently, it is up to date for TurboSphere version 0.2.1. It is sorted by which plugin the function is provided by, and contains lists for all the plugins included with the standard TurboSphere distribution.
Contents
Engine Functions
- RequireScript(filename)
- Compiles the indicated script and executes it.
- GetVersion()
- Returns a number representation of the version of TurboSphere. Until TurboSphere 1.0, this number does not have a fixed meaning.
- GetVersionString()
- Returns a string representation of the version of TurboSphere. This number also represents the versions of all the default plugins (they all share this same version number). For example: "0.2.2a"
Time Functions
- GetTime()
- Returns the number of milliseconds passed since a set point in time.
- Delay(ms)
- Idles the engine for 'ms' seconds. This cedes CPU time to other programs, and allows TurboSphere to use less than 100% of available CPU time.
GraphicSDL Functions
Screen Control
- FlipScreen()
- Draws the framebuffer to the screen. You must call this before anything you blit or draw will be visible.
- SetClippingRectangle(x, y, w, h)
- Sets the clipping rectangle of the screen.
- GetClippingRectangle()
- Returns and object with properties x, y, w, and h, that represents the clipping rectangle of the screen.
- SetTitle(title)
- Sets the title of the game window.
- GetScreenHeight()
- Returns the height of the game window in pixels.
- GetScreenWidth()
- Returns the width of the game window in pixels.
- SetResolution(w, h)
- Sets the game window's resolution to w, h.
Colors
- Color(r, g, b [, a])
- Creates a color object with the specified values. Alpha is optional.
- Example
- Creates a color object with the specified values. Alpha is optional.
var Red = new Color(255, 0, 0); //Red's alpha channel defaults to 255.
var NoColor = new Color(0, 0, 0, 0); //Fully transparent!
Surfaces and Images
- Image(...)
- Creates an image object that is held in video memory and handled by graphics hardware, if possible.
- Example
- Creates an image object that is held in video memory and handled by graphics hardware, if possible.
var image1 = new Image("imagefile.png"); //Creates an Image of the file imagefile.png in the images folder.
//or...
var image2 = new Image(16, 16, new Color(255, 0, 0, 255)); //Creates an Image of size 16 by 16 pixels filled with a red color.
- Surface
- Creates a surface object that is held in system memory and modified in software. Surfaces are faster than Images to modify (ie, with surface.setPixel or surface.rectangle), but slower to blit to the screen. Blits of surfaces onto images or images onto surfaces are much slower than blitting images onto images or surfaces onto surfaces.
- Example
- Creates a surface object that is held in system memory and modified in software. Surfaces are faster than Images to modify (ie, with surface.setPixel or surface.rectangle), but slower to blit to the screen. Blits of surfaces onto images or images onto surfaces are much slower than blitting images onto images or surfaces onto surfaces.
var surface1 = new Surface("imagefile.png"); //Creates a Surface of the file imagefile.png in the images folder.
//or...
var surface2 = new Surface(16, 16, new Color(255, 0, 0, 255)); //Creates a Surface of size 16 by 16 pixels filled with a red color.
- surface_or_image.getPixel(x, y)
- Returns a color object of the color of the Surface or Image at 'x', 'y'.
- surface_or_image.setPixel.(x, y, color)
- Sets the color of the pixel x, y of surface_or_image to 'color'.
- surface_or_image.rectangle(x, y, w, h, color)
- Draws a rectangle on surface_or_image at 'x', 'y', of width 'w' and height 'h' and fills it with 'color'.
- surface_or_image.zoomBlit(x, y, f)
- Blits surface_or_image at x, y, zoomed by factor f. A factor of 1 is the same as a normal blit.
- As of 0.2.2a, the surface is imperfectly drawn at factors not divisible by 1/2.
- surface_or_image.stretchBlit(x, y, hf, vh)
- Blits surface_or_image at x, y, with a horizontal scaling factor of hf and a vertical scaling factor of vf. Factors of 1 are the same as a normal blit.
- surface_or_image.blitSurface(surface_or_image_object, x, y)
- Blits surface_or_image_object onto surface_or_image at x, y.
- GetSystemArrow()
- Returns an image of the system arrow. The image used is set in system/system.ini.
Graphics Primitives
- Line(x1, y1, x2, y2, color)
- Draws a line of 'color' from x1, y1, to x2, y2.
- Point(x, y, color)
- Draws a point of 'color' at x, y.
- Rectangle(x, y, w, h, color)
- Draws a rectangle of 'color' width w and height h at x, y.
- GradientRectangle(x, y, w, h, c1, c2, c3, c4)
- Draws a rectangle at x, y, with a width of w and a height of h. The color is faded from c1 to c4 around the corners, moving clockwise from the upper left corner.
- FilledCircle(x, y, r, color)
- Draws a circle of radius r centered at x, y, filled with 'color'.
- OutlinedCircle(x, y, r, color
- Draws an outline of a circle of radius r centered at x, y with 'color'.
BMPFontSDL
- Font(filename)
- Creates a bmpfont object of the sphere rfn file 'filename' from the fonts folder.
var font1 = new Font("arial.rfn"); //font1 is a font object based on the font arial.rfn in the fonts folder.
var font2 = new Font("../../system/system.rfn"); //Opens the system rfn font. The actual; system font is not guaranteed to be this particular file.
- font.drawText(x, y, str)
- Draws 'str' using 'font' at 'x', 'y'.
- font.gatStringWidth(str)
- Returns the width of 'str' as drawn by 'font'.
- GetSystemFont()
- Returns a Font object representing the system font. The system font can be specified in the system/system.ini file, but by default is system/system.rfn.
TTFFontSDL
- TTFFont(filename)
- Creates a bmpfont object of the sphere rfn file 'filename' from the fonts folder.
var ttffont1 = new TTFFont("DejaVuSans.ttf"); //ttffont1 is a ttffont object based on the True Type font DejaVuSans.ttf in the fonts folder.
- ttffont.drawText(x, y, str)
- Draws 'str' using 'ttffont' at 'x', 'y'.
InputSDL
KeyBoard
Key Constants
- The following variables are defined for use as key constants:
KEY_ENTER
KEY_A
KEY_B
KEY_C
KEY_D
KEY_E
KEY_F
KEY_G
KEY_H
KEY_I
KEY_J
KEY_K
KEY_L
KEY_M
KEY_N
KEY_O
KEY_P
KEY_Q
KEY_R
KEY_S
KEY_T
KEY_U
KEY_V
KEY_W
KEY_X
KEY_Y
KEY_Z
KEY_TAB
KEY_ESCAPE
KEY_F1
KEY_F2
KEY_F3
KEY_F4
KEY_F5
KEY_F6
KEY_F7
KEY_F8
KEY_F9
KEY_F10
KEY_F11
KEY_F12
KEY_F13
KEY_F14
KEY_F15
KEY_TILDE
KEY_0
KEY_1
KEY_2
KEY_3
KEY_4
KEY_5
KEY_6
KEY_7
KEY_8
KEY_9
KEY_MINUS
KEY_EQUALS
KEY_BACKSPACE
KEY_SHIFT
KEY_RSHIFT
KEY_CAPSLOCK
KEY_NUMLOCK
KEY_SCROLLOCK
KEY_CTRL
KEY_RCTRL
KEY_ALT
KEY_RALT
KEY_SPACE
KEY_OPENBRACE
KEY_CLOSEBRACE
KEY_SEMICOLON
KEY_APOSTROPHE
KEY_COMMA
KEY_PERIOD
KEY_SLASH
KEY_BACKSLASH
KEY_INSERT
KEY_DELETE
KEY_HOME
KEY_END
KEY_PAGEUP
KEY_PAGEDOWN
KEY_UP
KEY_RIGHT
KEY_DOWN
KEY_LEFT
KEY_NUM_0
KEY_NUM_1
KEY_NUM_2
KEY_NUM_3
KEY_NUM_4
KEY_NUM_5
KEY_NUM_6
KEY_NUM_7
KEY_NUM_8
KEY_NUM_9
KEY_NUM_PERIOD
KEY_NUM_DIVIDE
KEY_NUM_MULTIPLY
KEY_NUM_MINUS
KEY_NUM_EQUALS
KEY_RMETA
KEY_LMETA
KEY_RSUPER
KEY_LSUPER
KEY_BREAK
KEY_MENU
KEY_POWER
KEY_EURO
Note that not all keys are available on all keyboards.
Keyboard Functions
- IsKeyPressed(key)
- Checks whether or not 'key', as expressed by a key constant, is pressed.
- IsAnyKeyPressed()
- Returns true if any key is pressed, false if not.
- GetKey()
- Returns a key from the key buffer. If no keys are available, waits until one is.
- AreKeysLeft()
- Checks whether there are keys in the key buffer.
Mouse
Mouse Button Constants
- The following mouse button constants are defined:
MOUSE_LEFT
MOUSE_RIGHT
MOUSE_MIDDLE
MOUSE_SUP
MOUSE_SDOWN
Mouse Functions
- GetMouseX()
- Returns the X coordinate of the mouse in the window.
- GetMouseY()
- Returns the Y coordinate of the mouse in the window.
- IsMouseButtonPressed(button)
- Checks whether or not 'button', as expressed by a mouse button constant, is pressed.
JoyStick Functions
Joystick Management
- GetNumJoysticks()
- Returns the number of available joysticks.
- GetJoystickName(n)
- Returns the name of joystick number 'n'.
Joystick Access
- GetNumJoystickButtons(n)
- Returns the number of buttons on joystick number 'n'.
- GetNumJoystickAxes(n)
- Returns the number of axes (ie, analog stick axes, analog triggers, throttles) on joystick number 'n'.
- IsJoystickButtonPressed(jsNum, buttonNum)
- Checks whether or not button number 'buttonNum' is pressed on joystick number 'jsNum'.
- GetJoystickAxis(jsNum, axisNum)
- Returns the position of axis number 'axisNum' on joystick number 'jsNum', between -32768 and 32767.
ScriptFS
FileSystem Function
- GetFileList(directory)
- Returns an array of filenames in the given directory. The base directory is the save directory, but you can use '..' to go up levels. There is no sandboxing, and you can access the entire filesystem of the computer with this function.
- RemoveFile(filename)
- Deletes the file 'filename'.
File Object
- File(filename)
- Returns a file object of 'filename'. If the file doesn't exist, it creates it.
- Example
- Returns a file object of 'filename'. If the file doesn't exist, it creates it.
var file1 = new File("save");
- file.read(key, default)
- Gets the value assigned to 'key' from 'file'. If 'key' does not exist, it creates it with the value 'default'.
- file.write(key, value)
- Writes 'value' and assigns it to 'key' in file. If the key already existed, it overwrites it.
- file.flush()
- Flushes changes to file, in case you don't want wait. Normally changes are flushed in a timely manner, and whenever the file is closed.
- file.close()
- Closes the handle to 'file', and flushes changes. 'file' can then be assigned a new value and used again.
- Example
- Closes the handle to 'file', and flushes changes. 'file' can then be assigned a new value and used again.
var file1 = new File("savefile1.save"); //create the file 'newfile.save' in the save directory.
file1.write("Lives", "3"); //write a value to the file.
file1.flush();
file1.close(); //Close the file.
//...
file1 = new File("savefile2.save"); //create another save file.
file1.write("Lives", "5"); //write a value to the file. Everyone knows the second save file is the best one.
file1.flush();
file1.close(); //Close the second file.
WindowStylesSDL
- WindowStyle(filename)
- Creates a WindowStyle from 'filename' in the windowstyles directory.
- Example
- Creates a WindowStyle from 'filename' in the windowstyles directory.
var ws1 = new WindowStyle("my_windowstyle.rws");
- windowstyle.drawWindow(x, y, w, h)
- Draws 'windowstyle' at 'x', 'y', with a width of 'w' and a height of 'h'.
GetKeyString
- getkeystring(key [, shift])
- Returns an ascii character that represents the key constant 'key'. If 'shift' is true, then it the character is represented as though the shift key is pressed.