RocRay
Program state err
Provide an initial state and a render function to the platform.
{ init : Task state []err, render : state -> Task state []err, }
PlatformState
A state record provided by platform on each frame.
{ timestampMillis : U64, frameCount : U64, keys : Keys.Keys, mouse : { position : Vector2, buttons : Mouse.Buttons, wheel : F32, }, }
KeyboardKey
Represents a keyboard key, like KeyA
or KeyEnter
.
Rectangle
Represents a rectangle.
{ x : F32, y : F32, width : F32, height : F32 }
Vector2
Represents a 2D vector.
{ x : F32, y : F32 }
Color
Represents a color using a tag union.
# a generic rgba color RGBA { r : U8, g : U8, b : U8, a : U8 } # predefined colors White Black Red Green Blue ... etc
Texture
A loaded texture resource, used to draw images.
Sound
A loaded sound resource, used to play audio.
Camera
A camera used to render a 2D perspective of the world.
rgba : Color -> InternalColor.RocColor
exit : Task {} *
Exit the program.
RocRay.exit!
log : Str, [ LogAll, LogTrace, LogDebug, LogInfo, LogWarning, LogError, LogFatal, LogNone ] -> Task {} *
Show a Raylib log trace message.
Raylib.log! "Not yet implemented" LogError
beginDrawing : Color -> Task {} *
Begin drawing to the framebuffer. Takes a color to clear the screen with.
RocRay.beginDrawing! White
endDrawing : Task {} *
End drawing to the framebuffer.
RocRay.endDrawing!
setWindowTitle : Str -> Task {} *
Set the window title.
RocRay.setWindowTitle! "My Roc Game"
setWindowSize : { width : F32, height : F32 } -> Task {} *
Set the window size.
RocRay.setWindowSize! { width: 800, height: 600 }
getScreenSize : Task { height : F32, width : F32 } *
Get the window size.
setTargetFPS : I32 -> Task {} *
Set the target frames per second. The default value is 60.
setDrawFPS : { fps : [ Visible, Hidden ], posX ? I32, posY ? I32 } -> Task {} *
Display the frames per second, and set the location. The default values are Hidden, 10, 10.
Raylib.setDrawFPS! { fps: Visible, posX: 10, posY: 10 }
measureText : { text : Str, size : I32 } -> Task I64 *
Measure the width of a text string using the default font.
drawText : { pos : { x : F32, y : F32 }, text : Str, size : I32, color : Color } -> Task {} *
Draw text on the screen using the default font.
RocRay.drawText! { pos: { x: 50, y: 120 }, text: "Click to start", size: 20, color: White }
drawLine : { start : Vector2, end : Vector2, color : Color } -> Task {} *
Draw a line on the screen.
RocRay.drawLine! { start: { x: 100, y: 500 }, end: { x: 500, y: 500 }, color: Red }
drawRectangle : { rect : Rectangle, color : Color } -> Task {} *
Draw a rectangle on the screen.
RocRay.drawRectangle! { rect: { x: 100, y: 150, width: 250, height: 100 }, color: Aqua }
drawRectangleGradientV : { rect : Rectangle, top : Color, bottom : Color } -> Task {} *
drawRectangleGradientH : { rect : Rectangle, top : Color, bottom : Color } -> Task {} *
Draw a rectangle with a horizontal-gradient fill on the screen.
RocRay.drawRectangleGradientH! { rect: { x: 400, y: 150, width: 250, height: 100 }, top: Lime, bottom: Navy }
drawCircle : { center : Vector2, radius : F32, color : Color } -> Task {} *
Draw a circle on the screen.
RocRay.drawCircle! { center: { x: 200, y: 400 }, radius: 75, color: Fuchsia }
drawCircleGradient : { center : Vector2, radius : F32, inner : Color, outer : Color } -> Task {} *
Draw a circle with a gradient on the screen.
RocRay.drawCircleGradient! { center: { x: 600, y: 400 }, radius: 75, inner: Yellow, outer: Maroon }
takeScreenshot : Str -> Task {} *
Takes a screenshot of current screen (filename extension defines format)
Raylib.takeScreenshot! "screenshot.png"
createCamera : { target : Vector2, offset : Vector2, rotation : F32, zoom : F32 } -> Task Camera *
Create a new camera. The camera can be used to render a 2D and 3D perspective of the world.
cameraSettings = { target: player, offset: { x: screenWidth / 2, y: screenHeight / 2 }, rotation: 0, zoom: 1, } cameraID = RocRay.createCamera! cameraSettings
updateCamera : Camera, { target : Vector2, offset : Vector2, rotation : F32, zoom : F32 } -> Task {} *
Update a camera's target, offset, rotation, and zoom.
cameraSettings = model.cameraSettings |> &target model.player |> &rotation rotation |> &zoom zoom RocRay.updateCamera! model.cameraID cameraSettings
beginMode2D : Camera -> Task {} *
Begin to draw a 2D scene using a camera.
Note you must call endMode2D
after drawing is complete or you will get an error.
Raylib.beginMode2D! camera
endMode2D : Camera -> Task {} *
End drawing a 2D scene using a camera.
Raylib.endMode2D! camera
loadTexture : Str -> Task Texture *
Load a texture from a file.
texture = Raylib.loadTexture! "sprites.png"
drawTextureRec : { texture : Texture, source : Rectangle, pos : Vector2, tint : Color } -> Task {} *
Draw part of a texture.
# Draw the sprite at the player's position. RocRay.drawTextureRec! { texture: model.dude, source: dudeSprite model.direction dudeAnimation.frame, pos: model.player, tint: White, }
loadSound : Str -> Task Sound *
Load a sound from a file.
wav = RocRay.loadSound "resources/sound.wav"
playSound : Sound -> Task {} *
Play a loaded sound.
RocRay.playSound! wav