Documentation for Wein2D.js



BoxCollision
Key
RenderCalls
RectangleRenderCall
OvalRenderCall
SpriteRenderCall
VirtualCanvasRenderCall
TextRenderCall
LineRenderCall
ClearRectangleRenderCall
Sound
Sprite
TextPositioning
VirtualCanvas
Wein2DApplication



class BoxCollision

Utility class for basic 2D box collision.


static rectTouchingRect(rect1PosX, rect1PosY, rect1SizeX, rect1SizeY, rect2PosX, rect2PosY, rect2SizeX, rect2SizeY)

Returns if a rectangle collides with a rectangle.

static pointInsideRect(pointX, pointY, rectPosX, rectPosY, rectSizeX, rectSizeY)

Returns if a point is inside a rectangle.

static rectInsideRect(rect1PosX, rect1PosY, rect1SizeX, rect1SizeY, rect2PosX, rect2PosY, rect2SizeX, rect2SizeY)

Returns if a rectangle is insde of a rectangle.



class Key

Describes a button on a keyboard.


static CTRL

Corresponds to the 'ctrl'-key on a keyboard.

static SHIFT

Corresponds to the 'shift'-key on a keyboard.

static SPACE

Corresponds to the spacebar on a keyboard.

static BACKSPACE

Corresponds to the backspace on a keyboard.

static ENTER

Corresponds to the enter-key / return-key on a keyboard.

static A

Corresponds to the 'a'-key on a keyboard.

static B

Corresponds to the 'b'-key on a keyboard.

static C

Corresponds to the 'c'-key on a keyboard.

static D

Corresponds to the 'd'-key on a keyboard.

static E

Corresponds to the 'e'-key on a keyboard.

static F

Corresponds to the 'f'-key on a keyboard.

static G

Corresponds to the 'g'-key on a keyboard.

static H

Corresponds to the 'h'-key on a keyboard.

static I

Corresponds to the 'i'-key on a keyboard.

static J

Corresponds to the 'j'-key on a keyboard.

static K

Corresponds to the 'k'-key on a keyboard.

static L

Corresponds to the 'l'-key on a keyboard.

static M

Corresponds to the 'm'-key on a keyboard.

static N

Corresponds to the 'n'-key on a keyboard.

static O

Corresponds to the 'o'-key on a keyboard.

static P

Corresponds to the 'p'-key on a keyboard.

static Q

Corresponds to the 'q'-key on a keyboard.

static R

Corresponds to the 'r'-key on a keyboard.

static S

Corresponds to the 's'-key on a keyboard.

static T

Corresponds to the 't'-key on a keyboard.

static U

Corresponds to the 'u'-key on a keyboard.

static V

Corresponds to the 'v'-key on a keyboard.

static W

Corresponds to the 'w'-key on a keyboard.

static X

Corresponds to the 'x'-key on a keyboard.

static Y

Corresponds to the 'y'-key on a keyboard.

static Z

Corresponds to the 'z'-key on a keyboard.

static UP

Corresponds to the arrow up on a keyboard.

static DOWN

Corresponds to the arrow down on a keyboard.

static LEFT

Corresponds to the arrow left on a keyboard.

static RIGHT

Corresponds to the arrow right on a keyboard.

static N0

Corresponds to the '0'-key on a keyboard.

static N1

Corresponds to the '1'-key on a keyboard.

static N2

Corresponds to the '2'-key on a keyboard.

static N3

Corresponds to the '3'-key on a keyboard.

static N4

Corresponds to the '4'-key on a keyboard.

static N5

Corresponds to the '5'-key on a keyboard.

static N6

Corresponds to the '6'-key on a keyboard.

static N7

Corresponds to the '7'-key on a keyboard.

static N8

Corresponds to the '8'-key on a keyboard.

static N9

Corresponds to the '9'-key on a keyboard.

static F1

Corresponds to the 'F1'-key on a keyboard.

static F2

Corresponds to the 'F2'-key on a keyboard.

static F3

Corresponds to the 'F3'-key on a keyboard.

static F4

Corresponds to the 'F4'-key on a keyboard.

static F5

Corresponds to the 'F5'-key on a keyboard.

static F6

Corresponds to the 'F6'-key on a keyboard.

static F7

Corresponds to the 'F7'-key on a keyboard.

static F8

Corresponds to the 'F8'-key on a keyboard.

static F9

Corresponds to the 'F9'-key on a keyboard.

static F10

Corresponds to the 'F10'-key on a keyboard.

static F11

Corresponds to the 'F11'-key on a keyboard.

static F12

Corresponds to the 'F12'-key on a keyboard.

static ESC

Corresponds to the escape-key on a keyboard.



class RenderCalls

Class that holds the rendering methods of Wein2D.


drawRectangle()

Returns a RectangleRenderCall that can be used to draw a rectangle.

drawOval()

Returns a OvalRenderCall that can be used to draw an oval.

drawSprite()

Returns a SpriteRenderCall that can be used to draw a sprite.

drawVirtualCanvas()

Returns a VirtualCanvasRenderCall that can be used to draw a sprite.

drawText()

Returns a TextRenderCall that can be used to draw text.

drawLine()

Returns a LineRenderCall that can be used to draw a line.

clearRectangle()

Returns a ClearRectangleRenderCall that can be used to draw a clearing rectangle (Sets all pixels inside the rectangle to (RGBA) -> [0,0,0,0].

fill(red, green, blue, optional_alpha)

Fills the screen in the given color.



class RectangleRenderCall

Class for simplification of rendering a rectangle.


setPosition(x, y)

Sets the position of the rectangle and returns itself.

setSize(width, height)

Sets the size of the rectangle and returns itself.

setColor(red, green, blue, optional_alpha)

Sets the color of the rectangle and returns itself (optional).

setAlpha(alpha)

Sets the alpha of the rectangle and returns itself (optional).

rotateDegrees(degreesAngle, optional_rotationCenterX, optional_rotationCenterY)

Rotates the rectangle and returns itself (optional).

rotateRadians(radiansAngle, optional_rotationCenterX, optional_rotationCenterY)

Rotates the rectangle and returns itself (optional).

draw()

Draws the rectangle onto the surface.



class OvalRenderCall

Class for simplification of rendering an oval.


setPosition(x, y)

Sets the position of the oval and returns itself.

setSize(width, height)

Sets the size of the oval and returns itself.

setColor(red, green, blue, optional_alpha)

Sets the color of the oval and returns itself (optional).

setAlpha(alpha)

Sets the alpha of the oval and returns itself (optional).

draw()

Draws the oval onto the surface.



class SpriteRenderCall

Class for simplification of rendering a Sprite.


setSprite(sprite)

Sets the sprite to be rendered and returns itself.

setPosition(x, y)

Sets the position of the sprite and returns itself.

setSize(width, height)

Sets the size of the sprite and returns itself.

setAlpha(alpha)

Sets the alpha of the sprite and returns itself (optional).

setSpriteCutoutDimensions(x, y, width, height)

Defines what part of the sprite should be rendered and returns itself (optional).

rotateDegrees(degreesAngle, optional_rotationCenterX, optional_rotationCenterY)

Rotates the sprite and returns itself (optional).

rotateRadians(radiansAngle, optional_rotationCenterX, optional_rotationCenterY)

Rotates the sprite and returns itself (optional).

draw()

Draws the Sprite onto the surface.



class VirtualCanvasRenderCall

Class for simplification of rendering a VirtualCanvas.


setVirtualCanvas(virtualCanvas)

Sets the VirtualCanvas to be rendered and returns itself.

setPosition(x, y)

Sets the position of the VirtualCanvas and returns itself.

setSize(width, height)

Sets the size of the VirtualCanvas and returns itself.

setAlpha(alpha)

Sets the alpha of the VirtualCanvas and returns itself (optional).

setCanvasCutoutDimensions(x, y, width, height)

Defines what part of the VirtualCanvas should be rendered and returns itself (optional).

rotateDegrees(degreesAngle, optional_rotationCenterX, optional_rotationCenterY)

Rotates the VirtualCanvas and returns itself (optional).

rotateRadians(radiansAngle, optional_rotationCenterX, optional_rotationCenterY)

Rotates the VirtualCanvas and returns itself (optional).

draw()

Draws the VirtualCanvas onto the surface.



class TextRenderCall

Class for simplification of rendering text.


setContent(content)

Sets the content to be rendered and returns itself.

setPosition(x, y)

Sets the position of the text and returns itself.

setSize(size)

Sets the size of the text and returns itself.

setPositioning(textPositioning)

Sets the orientation of the text relative to the position of the text and returns itself (optional).

setFontFamily(fontFamily)

Sets the font family used for rendering and returns itself (optional).

setColor(red, green, blue, optional_alpha)

Sets the color of the text and returns itself (optional).

setAlpha(alpha)

Sets the alpha of the text and returns itself (optional).

draw()

Draws the text onto the surface.



class LineRenderCall

Class for simplification of rendering a line.


setStart(x, y)

Sets the starting position of the line and returns itself.

setEnd(x, y)

Sets the ending position of the line and returns itself.

setWidth(width)

Sets the width of the line and returns itself.

setColor(red, green, blue, optional_alpha)

Sets the color of the line and returns itself (optional).

setAlpha(alpha)

Sets the alpha of the line and returns itself (optional).

draw()

Draws the line onto the surface.



class ClearRectangleRenderCall

Class for simplification of clearing pixels (setting to (RGBA) -> [0,0,0,0]) in shape of a rectangle.


setPosition(x, y)

Sets the position of the rectangle and returns itself.

setSize(width, height)

Sets the size of the rectangle and returns itself.

rotateDegrees(degreesAngle, optional_rotationCenterX, optional_rotationCenterY)

Rotates the rectangle and returns itself (optional).

rotateRadians(radiansAngle, optional_rotationCenterX, optional_rotationCenterY)

Rotates the rectangle and returns itself (optional).

draw()

Draws the rectangle onto the surface.



class Sound

Class for storing sound files and playing them.


constructor(filePath)

Creates a Sound from the specified file.

setVolume(volume)

Sets the Sound-object's volume. Also applies to sound already in playback. 'volume' should be a value between 0 and 1.

play()

Plays the sound. Starts from the beginning if already playing.

loop(looping)

Specifies if the sound should be looped infinitely.

stop()

Stops playback of the sound.

isPlaying()

Returns if the sound is currently played back.



class Sprite

Class for storing image files.


constructor(filePath)

Creates a Sprite from the specified file.

getWidth()

Returns the Sprite's width.

getHeight()

Returns the Sprite's height.

getImage()

Returns the Sprite as an image.



class TextPositioning

Describes the orientation of rendered Text.


static LEFT

Positions the text left of it's rendering coordinates.

static CENTER

Positions the text centered around it's rendering coordinates.

static RIGHT

Positions the text right of it's rendering coordinates.



class VirtualCanvas
extends RenderCalls

A virtual surface to draw onto. Can be drawn onto the main canvas afterwards.


constructor(width, height)

Creates a new VirtualCanvas with the specified dimensions.

getWidth()

Returns the width of the VirtualCanvas.

getHeight()

Returns the height of the VirtualCanvas.

getImage()

Returns the VirtualCanvas as an Image.

All fields from class RenderCalls



class Wein2DApplication
extends RenderCalls

Describes an application using Wein2DAndroid.


constructor(canvasElement, onFrameFunction)

Creates a Wein2dApplication-object with rendering to the specified element. Starts calling the specified function once per frame.

width

Stores the current width of the canvas. Gets overwritten at the beginning of every frame.

height

Stores the current height of the canvas. Gets overwritten at the beginning of every frame.

deltaTime

Stores the time in seconds since the last frame call. Gets overwritten at the beginning of every frame.

getKey(key)

Returns if the specified key is pressed down. Use the Key-class for specifying the key.

getTypedText()

Returns the last 1000 characters that have been after the page loaded.

setTypedText(text)

Sets the string that 'getTypedText()' returns.

getMouseX()

Returns the position of the mouse inside of the canvas on the x-axis.

getMouseY()

Returns the position of the mouse inside of the canvas on the y-axis.

getMouseL()

Returns if the left mouse button is currently pressed down.

getMouseS()

Returns if the scroll wheel is currently pressed down.

getMouseR()

Returns if the right mouse button is currently pressed down.

All fields from class RenderCalls



© Copyright 2022 DevTaube