Graphics(w, h, canvas, mode)

Start the application. You have to call this method before other method.
Parameters:
Name Type Default Description
w number 320 prefered width of the canvas. value 0 will be ignored
h number 240 prefered height of the canvas. Value 0 will be ignored
canvas HTMLCanvasElement null (optional) the canvas element.
If canvas is not available, a new one will be created and the size will follow the preferred size
mode boolean 1 (default to true) Use full screen When in full screen mode, the canvas will automatically fill the screen and maintain the aspect ratio.

Canvas() → {HTMLCanvasElement}

return the reference to canvas.
Returns:
Type
HTMLCanvasElement

SetCanvas(c)

Set the active canvas.
Parameters:
Name Type Description
c HTMLCanvasElement the new active canvas

Cls (x, y, x2, y2)

Clear the canvas
Parameters:
Name Type Default Description
x number 0 first x position
y number 0 first y position
x2 number canvas-width second x position
y2 number canvas height second y position

StrokeColor(r, g, b, a)

Set stroke color
Parameters:
Name Type Default Description
r number 0 the red color (0 - 255)
g number 0 the green color (0 - 255)
b number 0 the blue color (0 - 255)
a number 1 the alpha color (0 - 100)

FillColor(r, g, b, a)

Set fill-color for the next graphics command
Parameters:
Name Type Default Description
r number 0 the red color (0 - 255)
g number 0 the green color (0 - 255)
b number 0 the blue color (0 - 255)
a number 100 the alpha color (0 - 100)

SetPixel(x, y)

Set pixel using the color set by FillColor()
Parameters:
Name Type Default Description
x number 0 the x position
y number 0 the y position

GetPixel(x, y)

Get color information at the specific position.
You can read the red, green, blue, alpha component of the color by calling Red(), Green(), Blue(), Alpha() function respectively
Parameters:
Name Type Default Description
x number 0 the x position
y number 0 the y position

Alpha() → {number}

Return the alpha color component of the last color command. eg: GetPixel, FillColor, StrokeColor
Returns:
the alpha color (0 - 100)
Type
number

Red() → {number}

Return the red color component of the last color command. eg: GetPixel, FillColor, StrokeColor
Returns:
the red color (0 - 255)
Type
number

Blue() → {number}

Return the blue color component of the last color command. eg: GetPixel, FillColor, StrokeColor
Returns:
the blue color (0 - 255)
Type
number

Green() → {number}

Return the green color component of the last color command. eg: GetPixel, FillColor, StrokeColor
Returns:
the green color (0 - 255)
Type
number

AllImageLoaded() → {boolean}

Check if all images have been loaded
Returns:
Type
boolean

ClearArea(x, y, w, h)

Clear part of the canvas
Parameters:
Name Type Description
x number the start x position
y number the start y position
w number the width of the area
h number the height of the area
-->

CreateImage (width, height) → {Image}

Create a blank image
Parameters:
Name Type Description
width number width
height number height
Returns:
Type
Image

DrawImage(img)

Draw an image
Parameters:
Name Type Description
img Image Image to draw

FreeImage(img)

Delete and Image and All resource it uses
Parameters:
Name Type Description
img Image image to free

ImageCollide(img1, img2) → {boolean}

Check if two images collide. Use box for collision detection. Also Take account the rotation
Parameters:
Name Type Description
img1 Image the first image
img2 Image the second image
Returns:
Type
boolean

ImageCollidePoint(img, x, y) → {boolean}

Check if an image collides a point
Parameters:
Name Type Description
img Image the image
x number x test position
y number y test position
Returns:
Type
boolean

LoadImage(url) → {Image}

Load an image from url
Parameters:
Name Type Description
url string the url of image to load
Returns:
Type
Image

KeyboardIsDown(key) → {boolean}

Check if a key is being pressed
Parameters:
Name Type Description
key key to check
Returns:
Type
boolean

LastKey() → {string}

Return the last key for KeyboardEvent
Returns:
Type
string

LoadSound(url) → {Basik.Sound}

Load sound
Parameters:
Name Type Description
url string the url
Returns:
Type
Basik.Sound

PlaySound(s)

Play Sound
Parameters:
Name Type Description
s Sound sound object

MouseDragStartX() → {number}

drag start x position
Returns:
Type
number

MouseDragStartY() → {number}

drag start y position
Returns:
Type
number

MouseDraggedX() → {number}

drag horizontal length calculated from the drag start position
Returns:
Type
number

MouseDraggedY() → {number}

drag vertical length calculated from the drag start position
Returns:
Type
number

MouseIsDown() → {boolean}

muouse is down status
Returns:
Type
boolean

MouseIsDragged() → {boolean}

mouse is dragged
Returns:
Type
boolean

MouseMoveX() → {number}

return last mouse horizontal movement
Returns:
Type
number

MouseMoveY() → {number}

return last mouse vertical movement
Returns:
Type
number

MouseX() → {number}

mouse x position
Returns:
Type
number

MouseY() → {number}

mouse y position
Returns:
Type
number

Event

This function will execute automatically when it’s available and a specific event is triggered
Name Description
KeyboardDown User start pressing keyboard
KeyboardUp Keyboard is released
MouseDown User start pressing mouse button
MouseUp Mouse button released
MouseStartDrag Drag starts
MouseEndDrag Drag ends
MouseMove Mouse move
MouseClick Click
Update Application update
SoundEnded Sound finish playing

Object


Image

Properties:
Name Type Description
x number x position
y number y position
rotation number rotation in degree
alpha number alpha (0 - 100)
width number preferred width
height number preferred height
handleX number handle x position
handleY number handle y position
tilable boolean image rendered as tile
dragged boolean image is dragged
down boolean image is pressed
loaded boolean image is loaded