Skip to content

Instantly share code, notes, and snippets.

@joskuijpers
Last active August 29, 2015 13:57
Show Gist options
  • Save joskuijpers/9712448 to your computer and use it in GitHub Desktop.
Save joskuijpers/9712448 to your computer and use it in GitHub Desktop.
Sphere OO API
=== SYSTEM ===
GetVersion System.version
GetVersionString System.versionString
Abort System.abort(msg)
Exit System.exit()
RestartGame System.restart()
System.sleep(double seconds)
GarbageCollect System.Debug.garbageCollect() // Warning: blocking
EvalualteSystemScript <folded>
EvaluateScript include(path) // searches in order:scripts/, libraries/*/scripts, ./, system/scripts
RequireSystemScript <folded>
RequireScript require(path) // searches in order:scripts/, libraries/*/scripts, ./, system/scripts
=== TIME ===
GetTime System.milliseconds()
System.getCurrentTime()
=== GAME OBJECT ===
Listing games is removed. Each game is packaged separately so game listing is useless.
The shim will return a list with only the current game. ExecuteGame does nothing.
Game <removed>
GetGameList <removed>
ExecuteGame <removed>
=== SCREEN ===
FlipScreen Screen.flip()
Apply color mask Screen.applyColorMask(c)
GetScreenWidth Screen.width
GetScreenHeight Screen.height
point Screen.drawPoint(x,y,c)
point series Screen.drawPoints(array,c)
line Screen.drawLine(x1,y1,x2,y2,c)
gradient line Screen.drawLine(x1,y1,x2,y2,c1,c2)
line series Screen.drawLines(array,c)
BezierCurve Screen.drawBezierCurve(color, step, Ax, Ay, .... D)
Polygon Screen.drawPolygon(array, color [,invert])
Triangle Screen.drawTriangle(x1,y1,x2,y2,x3,y3,c)
FilledTriangle Screen.drawFilledTriangle(x1,y1,x2,y2,x3,y3,c)
GraidnetTriangle Screen.drawFilledTriangle(x1,y1,x2,y2,x3,y3,c1,c2,c3)
Draw outlined rect Screen.drawRect(x,y,w,h,c)
Draw filled rect Screen.drawFilledRect(x,y,w,h,c)
Draw gradient rect Screen.drawFilledRect(x,y,w,h,c_ul,c_ur,c_lr,c_ll)
Draw outlined Circle Screen.drawCircle(x,y,r) // calls ellipse
Draw filled Circle Screen.drawFilledCircle(x,y,r,c1) // calls ellipse
Draw gradient circle Screen.drawFilledCircle(x,y,r,c1,c2) // calls ellipse
Draw outlined ellipse Screen.drawEllipse(x,y,rx,ry,c)
Draw filled ellipse Screen.drawFilledEllipse(x,y,rx,ry,c)
Draw graidnet ellipse Screen.drawFilledEllipse(x,y,rx,ry,c1,c2)
Outlined complex Screen.drawComplex(rz,ry,rw,rh,cx,cy,cr,color)
Filled complex Screen.drawFilledComplex(rz,ry,rw,rh,cx,cy,cr,ca,cf,fill_empty,color1,color2)
Gradient complex Screen.drawFilledComplex(rz,ry,rw,rh,cx,cy,cr,ca,cf,fill_empty,color1,color2,color3)
=== INPUT OBJECT ===
== GAMEPAD ==
Get a joystick Input.gamepads[i] //r
GetNumJoysticks Input.gamepads.length //r
GetNumJoystickButtons Input.Gamepad.prototype.numberOfButons //r
GetNumJoystickAxes Input.Gamepad.prototype.numberOfAxis //r
Get/Set TalkActivationButton Input.Gamepad.prototype.talkActivationButton //rw
IsJoystickButtonPressed Input.Gamepad.prototype.isButtonPressed(i) //B
GetJoystickAxis Input.Gamepad.prototype.getAxis(a) //I
Gamepad.AXIS_X, Gamepad.AXIS_Y, /*Gamepad.AXIS_Z, Gamepad.AXIS_R*/
== Mouse ==
GetMouseX Input.Mouse.x //r
GetMouseY Input.Mouse.y //r
SetMousePosition Inout.Mouse.setPosition(x,y)
IsMouseButtonPressed Input.Mouse.isButtonPressed(b) //r,B
Input.Mouse.numberOfButtons //r
GetMouseWheelEvent Input.Wheel.getEvent() // 'pop', event OR Input.getWheelEvent()
GetNumMouseWheelEvents <removed>
Input.Wheel.clearQueue()
Input.Wheel.UP=3, DOWN=4 OR Input.Mouse.WHEEL_UP/WHEEL_DOWN.
Input.Mouse.BUTTON_LEFT=0,BUTTON_MIDDLE=1,BUTTON_RIGHT=2
== Keyboard ==
GetPlayerKey Input.Config.players[player] // PlayerInputConfig
System.PlayerInputConfig
.menu,.up,.down,.left,.right,.a,.b,.x,.y
AreKeysLeft <folded>
GetKey Input.Keyboard.getKey() //key
IsAnyKeyPressed Input.Keyboard.isKeyPressed() //B
IsKeyPressed Input.Keyboard.isKeyPressed(k) //B
GetToggleState Input.Keyboard.getToggleState(tk) //B
GetKeyString Input.Keyboard.getKeyString(k) //String
Input.Keyboard.clearQueue()
Input.Keyboard.KEY_SHIFT, .KEY_A
=== SOUND SYSTEM ===
Sound and SoundEffect object just like Sphere 1.5, but with constructors.
LoadSound new Sound()
LoadSoundEffect new SoundEffect()
=== NETWORKING ===
GetLocalAddress Network.localAddress
GetLocalName Network.localName
ListenOnPort Network.listenOnPort(p,cb) //B, callback(error,acceptSocket)
OpenAddress new Network.Socket(a,p)
== Socket ==
WARNING: The Socket API will be rewritten to be Async. But that is a WIP. It will be based on Sockets.io
close Network.Socket.prototype.close()
getPendingReadSize Network.Socket.prototype.pendingReadSize //r
isConnected Network.Socket.prototype.connected //r
read Network.Socket.prototype.read(s) // ByteArrar
write Network.Socket.prototype.write(ba)
== Bonjour ==
new Network.Bonjour([type=_game._tcp [,domain=local]])
Network.Bonjour.prototype.type //r
Network.Bonjour.prototype.domain //r
Network.Bonjour.prototype.publish(port,name[,cb]) //B, callback(status)
Network.Bonjour.prototype.discover(cb) // callback(error,Network.Bonjour.Peer peer)
Network.Bonjour.prototype.resolve(name,cb) // callback(error,host,port)
Network.Bonjour.prototype.stop()
Network.Bonjour.Peer.prototype.name //r
Network.Bonjour.Peer.prototype.resolve(cb) // callback(error,host,port)
Network.Bonjour.Peer.prototype.getSocket() // Network.Socket
=== MAP ENGINE ===
TODO
=== SPRITESET ===
LoadSpriteset new Spriteset(path)
CreateSpriteset new Spriteset(fw,fh,ni,nd,nf)
save()
clone
base //rw
directions[] // Direction
images[]
Direction
frames[] // Frame
name //rw
Frame
image //rw
delay //rw
=== FONT ===
GetSystemFont Font.systemFont
LoadFont new Font('path')
save Font.prototype.save([path]) // or use path loaded with
drawText Font.prototype.draw(x,y,t)
drawZoomedText Font.prototype.draw(x,y,t,s/*float*/)
drawTextBox Font.prototype.drawBox(x,y,w,h,yoff,t)
wordWrapString Font.prototype.wordWrap(s,w) // Array
getHeight Font.prototype.characterHeight //r
getStringWidth Font.prototype.getStringWidth(str)
getStringHeight <dropped>
setColorMask
getColorMask Font.prototype.colorMask //rw, Color
getCharacterImage <folded>
setCharacterImage Font.prototype.characters[code] //rw, Image
=== WINDOW STYLES ===
GetSystemWindowStyle WindowStyle.systemStyle
LoadWindowStyle new WindowStyle(path)
drawWindow WindowStyle.prototype.draw(x,y,w,h)
getColorMask
setColorMask WindowStyle.prototype.colorMask //rw, Color
=== IMAGE ===
LoadImage new Image(path)
GrabImage new Image(x,y,w,h)
GetSystemArrow Image.systemArrow
GetSystemUpArrow Image.systemUpArrow
GetSystemDownArrow Image.systemDownArrow
clone Image.prototype.clone()
blit Image.prototype.blit(x,y)
blitMask Image.prototype.blit(x,y,color)
zoomBlit Image.prototype.blit(x,y,s)
zoomBlitMask Image.prototype.blit(x,y,s,color)
rotateBlit Image.prototype.blitRotated(cx,cy,angle)
rotateBlitMask Image.prototype.blitRotated(cx,cy,angle,color)
transformBlit Image.prototype.blit(x1,y1,x2,y2,x3,y3,x4,y4)
transformBlitMask Image.prototype.blit(x1,y1,x2,y2,x3,y3,x4,y4,color)
createSurface Image.prototype.toSurface() //Surface
=== SURFACE ===
TODO
=== ANIMATION ===
LoadAnimation new Animation(path)
readNextFrame <unknown>
drawFrame Animation.prototype.draw(x,y)
drawZoomedFrame Animation.prototype.draw(x,y,s)
getDelay Animation.prototype.delay //r
getNumFrames Animation.prototype.frames.length //r
=== FileSystem ===
GetDirectoryList <folded in GetFileList>
GetFileList FileSystem.list(path)
FileSystem.Directory.prototype.list(path)
RemoveFile FileSystem.remove(path)
FileSystem.File.prototype.remove()
Rename FileSystem.rename(old,new)
FileSystem.{Raw}File.prototype.rename(new)
FileSystem.Directory.prototype.rename(new)
CreateDirectory FileSystem.createDirectory(path)
RemoveDirectory FileSystem.Directory.prototype.remove()
FileSystem.remove(path)
FileSystem.exists(path) //B
HashFromFile FileSystem.md5(path)
FileSystem.sha1(path)
FileSystem.sha256(path)
== File ==
OpenFile new FileSystem.File(path)
read FileSystem.File.prototype.read(k,d)
write FileSystem.File.prototype.write(k,v)
flush FileSystem.File.prototype.flush()
close FileSystem.File.prototype.close()
getNumKeys FileSystem.File.prototype.size;
getKey <removed>
FileSystem.File.prototype.path //r
FileSystem.File.prototype.keys //Array of Strings
FileSystem.File.prototype.hasKey(k) //B
FileSystem.File.prototype.rename(new)
FileSystem.File.prototype.remove()
FileSystem.File.prototype.md5hash()
FileSystem.File.prototype.sha1hash()
FileSystem.File.prototype.sha256hash()
== RawFile ==
OpenRawFile new FileSystem.RawFile(path)
read FileSystem.RawFile.prototype.read(size) //ByteArray
write FileSystem.RawFile.prototype.write(byte_array)
close FileSystem.RawFile.prototype.close()
getSize FileSystem.RawFile.prototype.size //r
getPosition <folded>
setPosition FileSystem.RawFile.prototype.position //rw
FileSystem.File.prototype.path //r
FileSystem.RawFile.prototype.writeable //r
FileSystem.RawFile.prototype.rename(new)
FileSystem.RawFile.prototype.remove()
FileSystem.RawFile.prototype.md5hash()
FileSystem.RawFile.prototype.sha1hash()
FileSystem.RawFile.prototype.sha256hash()
== Directory ==
new FileSystem.Directory(path)
FileSystem.Directory.prototype.list()
FileSystem.Directory.prototype.path //r
FileSystem.Directory.prototype.rename(new)
FileSystem.Directory.prototype.remove()
=== ByteArray ===
CreateByteArray new ByteArray(l)
concat ByteArray.prototype.concat(ba)
slice ByteArray.prototype.slice(s,e)
CreateByteArrayFromString new ByteArray(s)
CreateStringFromByteArray ByteArray.prototype.makeString()
HashByteArray ByteArray.prototype.md5hash()
ByteArray.prototype.sha1hash()
ByteArray.prototype.sha256hash()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment