wCanvas

wCanvas

Wraps a Canvas and provides useful functions

Constructor

new wCanvas(configopt)

Source:
Parameters:
Name Type Attributes Description
config wCanvasConfig <optional>

The config to create the wCanvas with

Classes

wCanvas

Members

(constant) context :CanvasRenderingContext2D

The 2D drawing context of wCanvas#element

Source:
Type:
  • CanvasRenderingContext2D

(constant) element :HTMLCanvasElement

The native canvas element

Source:
Type:
  • HTMLCanvasElement

onDraw :wCanvas_onDraw

The function to call on draw event

Source:
Type:

onResize :wCanvas_onResize

The function to call on resize event

Source:
Type:

onSetup :wCanvas_onSetup

The function to call on setup event

Source:
Type:

targetFPS :Number

The target FPS of the canvas (If it's a negative value it will try to draw every time it's possible)

Source:
Type:
  • Number

Methods

background(ropt, gopt, bopt, aopt) → {undefined}

Draws a rectangle that fills the entire canvas using the specified color

Source:
Parameters:
Name Type Attributes Default Description
r Number | Color <optional>
0

Red [0, 255] if not a number it's treated as a Color

g Number <optional>
0

Green [0, 255]

b Number <optional>
0

Blue [0, 255]

a Number <optional>
255

Alpha [0, 255]

Returns:
Type:
undefined

circle(x, y, r, configopt) → {undefined}

Draws a circle at the specified location with the specified properties

Source:
Parameters:
Name Type Attributes Description
x Number

The x coordinate where the circle should be drawn

y Number

The y coordinate where the circle should be drawn

r Number

The radius of the circle

config ShapeConfig <optional>

Other options

Returns:
Type:
undefined

clear() → {undefined}

Clears the whole canvas

Source:
Returns:
Type:
undefined

ellipse(x, y, rX, rYopt, configopt) → {undefined}

Draws an ellipse at the specified location with the specified properties

Source:
Parameters:
Name Type Attributes Description
x Number

The x coordinate where the ellipse should be drawn

y Number

The y coordinate where the ellipse should be drawn

rX Number

The radius on the x axis of the ellipse

rY Number <optional>

The radius on the y axis of the ellipse (Same as rX if undefined)

config ShapeConfig <optional>

Other options

Returns:
Type:
undefined

fill(ropt, gopt, bopt, aopt) → {undefined}

Sets the color to be used to fill shapes

Source:
Parameters:
Name Type Attributes Default Description
r Number | Color <optional>
255

Red [0, 255] if not a number it's treated as a Color

g Number <optional>
255

Green [0, 255]

b Number <optional>
255

Blue [0, 255]

a Number <optional>
255

Alpha [0, 255]

Returns:
Type:
undefined

isLooping() → {Boolean}

Whether or not this canvas's draw loop is running

Source:
Returns:
Type:
Boolean

line(x1, y1, x2, y2, roundopt) → {undefined}

Draws a line from x1, y1 to x2, y2

Source:
Parameters:
Name Type Attributes Default Description
x1 Number

The starting x coordinate

y1 Number

The starting y coordinate

x2 Number

The end x coordinate

y2 Number

The end y coordinate

round Boolean <optional>
true

Whether or not line ends should be rounded

Returns:
Type:
undefined

path(xopt, yopt, vertices, configopt) → {undefined}

Draws a shape using the specified vertices (Tries to draw only if there are 2 or more vertices specified)

Source:
Parameters:
Name Type Attributes Default Description
x Number <optional>
0

The x pos from where the path should be drawn

y Number <optional>
0

The y pos from where the path should be drawn

vertices Array.<Array.<Number>> | Array.<UMath.Vec2> | Array.<Vec2Object>

Array of Vertices (A vertex is this kind of array [x, y])

config PathConfig <optional>

Other options

Returns:
Type:
undefined

rect(x, y, w, h, configopt) → {undefined}

Draws a rectangle at the specified location with the specified properties

Source:
Parameters:
Name Type Attributes Description
x Number

The x coordinate where the rectangle should be drawn

y Number

The y coordinate where the rectangle should be drawn

w Number

The width of the rectangle

h Number

The height of the rectangle

config RectConfig <optional>

Other options

Returns:
Type:
undefined

restore(nopt) → {undefined}

Restores canvas context from last save (Using wCanvas#context#restore is better if you don't need to restore the context multiple times)

Source:
Parameters:
Name Type Attributes Default Description
n Number <optional>
1

How many times the context should be restored

Returns:
Type:
undefined

rotate(angleopt) → {undefined}

Rotates every next shape by the specified angle in radians (Using wCanvas#context#rotate is better if you don't need the default values)

Source:
Parameters:
Name Type Attributes Default Description
angle Number <optional>
0

Angle in radians

Returns:
Type:
undefined

save(nopt) → {undefined}

Saves canvas context to be restored at a later date (Using wCanvas#context#save is better if you don't need to save the context multiple times)

Source:
Parameters:
Name Type Attributes Default Description
n Number <optional>
1

How many times the context should be saved

Returns:
Type:
undefined

scale(xopt, yopt) → {undefined}

Scales every next shape by the specified values (Using wCanvas#context#scale is better if you don't need the default values)

Source:
Parameters:
Name Type Attributes Default Description
x Number <optional>
1

Horizontal Scale

y Number <optional>

Vertical Scale (Same as X if undefined)

Returns:
Type:
undefined

startLoop() → {undefined}

Starts draw loop (Doesn't do that if one was already started)

Source:
Returns:
Type:
undefined

stopLoop() → {undefined}

Stops draw loop

Source:
Returns:
Type:
undefined

stroke(ropt, gopt, bopt, aopt) → {undefined}

Sets the color to be used for shapes contours

Source:
Parameters:
Name Type Attributes Default Description
r Number | Color <optional>
0

Red [0, 255] if not a number it's treated as a Color

g Number <optional>
0

Green [0, 255]

b Number <optional>
0

Blue [0, 255]

a Number <optional>
255

Alpha [0, 255]

Returns:
Type:
undefined

strokeWeight(dopt) → {undefined}

Changes stroke diameter (Setting wCanvas#context#lineWidth is better if you don't need the default values)

Source:
Parameters:
Name Type Attributes Default Description
d Number <optional>
1

The diameter of the stroke

Returns:
Type:
undefined

text(text, x, y, configopt) → {undefined|Number}

Draws the specified text at the specified coordinates

Source:
Parameters:
Name Type Attributes Description
text String

The text to be written

x Number

The x coordinate where the text should be drawn

y Number

The y coordinate where the text should be drawn

config TextConfig <optional>

Other options

Returns:
Type:
undefined | Number

If config.returnWidth is true it returns the text's width

textFont(fontopt) → {undefined}

Changes font

Source:
Parameters:
Name Type Attributes Description
font Font <optional>

The new font to use

Returns:
Type:
undefined

textSize(sizeopt) → {undefined}

Changes font's size

Source:
Parameters:
Name Type Attributes Default Description
size Number <optional>
12

The new size for the font

Returns:
Type:
undefined

translate(xopt, yopt) → {undefined}

Translates every next shape by the specified offset (Using wCanvas#context#translate is better if you don't need the default values)

Source:
Parameters:
Name Type Attributes Default Description
x Number <optional>
0

X translation

y Number <optional>

Y translation (Same as X if undefined)

Returns:
Type:
undefined